Java Code Examples for org.javamoney.moneta.FastMoney#of()
The following examples show how to use
org.javamoney.moneta.FastMoney#of() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AmountsDoCalculations.java From javamoney-examples with Apache License 2.0 | 6 votes |
/** * @param args */ public static void main(String[] args) { MonetaryAmount amount = Monetary.getDefaultAmountFactory().setCurrency("EUR").setNumber(234).create(); ConsoleUtils.printDetails(amount); amount = Monetary.getAmountFactory(FastMoney.class).setCurrency("EUR").setNumber(234).create(); ConsoleUtils.printDetails(amount); amount = Monetary.getAmountFactory( MonetaryAmountFactoryQueryBuilder.of().setMaxScale(50).setPrecision(30).build()) .setCurrency("EUR").setNumber(234).create(); ConsoleUtils.printDetails(amount); Money amt1 = Money.of(10.1234556123456789, "USD"); FastMoney amt2 = FastMoney.of(123456789, "USD"); Money total = amt1.add(amt2).multiply(0.5) .remainder(1); ConsoleUtils.printDetails(total); }
Example 2
Source File: AmountsDoCalculations.java From javamoney-examples with Apache License 2.0 | 6 votes |
/** * @param args */ public static void main(String[] args) { var amount = Monetary.getDefaultAmountFactory().setCurrency("EUR").setNumber(234).create(); ConsoleUtils.printDetails(amount); amount = Monetary.getAmountFactory(FastMoney.class).setCurrency("EUR").setNumber(234).create(); ConsoleUtils.printDetails(amount); amount = Monetary.getAmountFactory( MonetaryAmountFactoryQueryBuilder.of().setMaxScale(50).setPrecision(30).build()) .setCurrency("EUR").setNumber(234).create(); ConsoleUtils.printDetails(amount); var amt1 = Money.of(10.1234556123456789, "USD"); var amt2 = FastMoney.of(123456789, "USD"); var total = amt1.add(amt2).multiply(0.5) .remainder(1); ConsoleUtils.printDetails(total); }
Example 3
Source File: MonetaryFormatsTest.java From jsr354-ri with Apache License 2.0 | 6 votes |
/** * Tests formatting and parsing back the values using all available locales. */ @Test public void testRoundRobinForAllLocales_FastMoney(){ String report = ""; Locale defaultLocale = Locale.getDefault(); try { for (Locale locale : Locale.getAvailableLocales()) { Locale.setDefault(locale); try { FastMoney money = FastMoney.of(1.2, "EUR"); if (!money.equals(FastMoney.parse(money.toString()))) { report += "FAILED : " + locale + "(" + money.toString() + ")\n"; } else { report += "SUCCESS: " + locale + "\n"; } }catch(Exception e){ report += "ERROR: " + locale + " -> " + e + "\n"; } } assertFalse(report.contains("FAILED"),"Formatting and parsing failed for some locales:\n\n"+report); }finally{ Locale.setDefault(defaultLocale); } }
Example 4
Source File: JavaMoneyUnitManualTest.java From tutorials with MIT License | 6 votes |
@Test public void givenAmounts_whenStringified_thanEquals() { CurrencyUnit usd = Monetary.getCurrency("USD"); MonetaryAmount fstAmtUSD = Monetary .getDefaultAmountFactory() .setCurrency(usd) .setNumber(200) .create(); Money moneyof = Money.of(12, usd); FastMoney fastmoneyof = FastMoney.of(2, usd); assertEquals("USD", usd.toString()); assertEquals("USD 200", fstAmtUSD.toString()); assertEquals("USD 12", moneyof.toString()); assertEquals("USD 2.00000", fastmoneyof.toString()); }
Example 5
Source File: AmountsDoCalculations.java From javamoney-examples with Apache License 2.0 | 6 votes |
/** * @param args */ public static void main(String[] args) { MonetaryAmount amount = Monetary.getDefaultAmountFactory().setCurrency("EUR").setNumber(234).create(); ConsoleUtils.printDetails(amount); amount = Monetary.getAmountFactory(FastMoney.class).setCurrency("EUR").setNumber(234).create(); ConsoleUtils.printDetails(amount); amount = Monetary.getAmountFactory( MonetaryAmountFactoryQueryBuilder.of().setMaxScale(50).setPrecision(30).build()) .setCurrency("EUR").setNumber(234).create(); ConsoleUtils.printDetails(amount); Money amt1 = Money.of(10.1234556123456789, "USD"); FastMoney amt2 = FastMoney.of(123456789, "USD"); Money total = amt1.add(amt2).multiply(0.5) .remainder(1); ConsoleUtils.printDetails(total); }
Example 6
Source File: LiteralTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint() throws IOException { LiteralToken token = new LiteralToken(" some text "); FastMoney amount = FastMoney.of(0,"USD"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), " some text "); }
Example 7
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_SYMBOL_EUR_for_US() throws IOException { CurrencyToken token = new CurrencyToken(SYMBOL, AmountFormatContextBuilder.of(US).build()); FastMoney amount = FastMoney.of(0, "EUR"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "€"); // for some reason here is returned a symbol € instead of EUR }
Example 8
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_SYMBOL_USD() throws IOException { CurrencyToken token = new CurrencyToken(SYMBOL, AmountFormatContextBuilder.of(US).build()); FastMoney amount = FastMoney.of(0, "USD"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "$"); }
Example 9
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_SYMBOL_BGN_for_US() throws IOException { CurrencyToken token = new CurrencyToken(SYMBOL, AmountFormatContextBuilder.of(US).build()); FastMoney amount = FastMoney.of(0, "BGN"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "BGN"); }
Example 10
Source File: AmountNumberTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_US() throws IOException { AmountNumberToken token = new AmountNumberToken(contextForLocale(US, null), PATTERN); FastMoney amount = FastMoney.of(-42.00,"USD"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "-42.00 "); }
Example 11
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_SYMBOL_HKD() throws IOException { CurrencyToken token = new CurrencyToken(SYMBOL, AmountFormatContextBuilder.of(new Locale("en", "HK")).build()); FastMoney amount = FastMoney.of(0, "HKD"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "HK$"); }
Example 12
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_SYMBOL_RUB_for_US() throws IOException { CurrencyToken token = new CurrencyToken(SYMBOL, AmountFormatContextBuilder.of(US).build()); FastMoney amount = FastMoney.of(0, "RUB"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "RUB"); }
Example 13
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_NAME_USD_for_US() throws IOException { CurrencyToken token = new CurrencyToken(NAME, AmountFormatContextBuilder.of(US).build()); FastMoney amount = FastMoney.of(0, "USD"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "US Dollar"); }
Example 14
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_SYMBOL_BGN() throws IOException { CurrencyToken token = new CurrencyToken(SYMBOL, AmountFormatContextBuilder.of(new Locale("bg", "BG")).build()); FastMoney amount = FastMoney.of(0, "BGN"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "лв."); }
Example 15
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_SYMBOL_GBP_for_France() throws IOException { CurrencyToken token = new CurrencyToken(SYMBOL, AmountFormatContextBuilder.of(FRANCE).build()); FastMoney amount = FastMoney.of(0, "GBP"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "£GB"); }
Example 16
Source File: FastMoneyAmountFactory.java From jsr354-ri with Apache License 2.0 | 4 votes |
@Override protected FastMoney create(Number number, CurrencyUnit currency, MonetaryContext monetaryContext) { return FastMoney.of(number, currency); }
Example 17
Source File: BigDecimalColumnFastMoneyMapper.java From jadira with Apache License 2.0 | 4 votes |
@Override public FastMoney fromNonNullValue(BigDecimal val) { return FastMoney.of(val, currencyUnit); }
Example 18
Source File: LongColumnFastMoneyMinorMapper.java From jadira with Apache License 2.0 | 4 votes |
@Override public FastMoney fromNonNullValue(Long val) { BigDecimal minorVal = BigDecimal.valueOf(val, currencyUnit.getDefaultFractionDigits()); return FastMoney.of(minorVal, currencyUnit); }
Example 19
Source File: PersistentFastMoneyMinorAmountAndCurrency.java From jadira with Apache License 2.0 | 3 votes |
@Override protected FastMoney fromConvertedColumns(Object[] convertedColumns) { CurrencyUnit currencyUnitPart = (CurrencyUnit) convertedColumns[0]; Long amountMinorPart = (Long) convertedColumns[1]; BigDecimal majorVal = BigDecimal.valueOf(amountMinorPart, currencyUnitPart.getDefaultFractionDigits()); return FastMoney.of(majorVal, currencyUnitPart); }
Example 20
Source File: LongColumnFastMoneyMinorMapper.java From jadira with Apache License 2.0 | 3 votes |
@Override public FastMoney fromNonNullString(String s) { int separator = s.indexOf(' '); String currency = s.substring(0, separator); String value = s.substring(separator + 1); return FastMoney.of(Long.parseLong(value), Monetary.getCurrency(currency)); }