org.javamoney.moneta.FastMoney Java Examples
The following examples show how to use
org.javamoney.moneta.FastMoney.
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: AmountEntry.java From javamoney-examples with Apache License 2.0 | 6 votes |
public void setAmount(MonetaryAmount amount) { if (amount != null) { codeBox.getSelectionModel().select( amount.getCurrency().getCurrencyCode()); if (FastMoney.class.equals(amount.getClass())) { numberType.getSelectionModel().select("Long"); } else { numberType.getSelectionModel().select("BigDecimal"); } numberValue.setText(Money.from(amount).getNumber() .toString()); } else { codeBox.getSelectionModel().clearSelection(); numberType.getSelectionModel().clearSelection(); numberValue.setText("0"); } }
Example #2
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 #3
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 #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: MoneyModule.java From jackson-datatype-money with MIT License | 6 votes |
private MoneyModule(final AmountWriter<?> writer, final FieldNames names, final MonetaryAmountFormatFactory formatFactory, final MonetaryAmountFactory<? extends MonetaryAmount> amountFactory, final MonetaryAmountFactory<FastMoney> fastMoneyFactory, final MonetaryAmountFactory<Money> moneyFactory, final MonetaryAmountFactory<RoundedMoney> roundedMoneyFactory) { this.writer = writer; this.names = names; this.formatFactory = formatFactory; this.amountFactory = amountFactory; this.fastMoneyFactory = fastMoneyFactory; this.moneyFactory = moneyFactory; this.roundedMoneyFactory = roundedMoneyFactory; }
Example #7
Source File: MoneyModule.java From jackson-datatype-money with MIT License | 6 votes |
@Override public void setupModule(final SetupContext context) { final SimpleSerializers serializers = new SimpleSerializers(); serializers.addSerializer(CurrencyUnit.class, new CurrencyUnitSerializer()); serializers.addSerializer(MonetaryAmount.class, new MonetaryAmountSerializer(names, writer, formatFactory)); context.addSerializers(serializers); final SimpleDeserializers deserializers = new SimpleDeserializers(); deserializers.addDeserializer(CurrencyUnit.class, new CurrencyUnitDeserializer()); deserializers.addDeserializer(MonetaryAmount.class, new MonetaryAmountDeserializer<>(amountFactory, names)); // for reading into concrete implementation types deserializers.addDeserializer(Money.class, new MonetaryAmountDeserializer<>(moneyFactory, names)); deserializers.addDeserializer(FastMoney.class, new MonetaryAmountDeserializer<>(fastMoneyFactory, names)); deserializers.addDeserializer(RoundedMoney.class, new MonetaryAmountDeserializer<>(roundedMoneyFactory, names)); context.addDeserializers(deserializers); }
Example #8
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 #9
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_SYMBOL_EUR() throws IOException { CurrencyToken token = new CurrencyToken(SYMBOL, AmountFormatContextBuilder.of(FRANCE).build()); FastMoney amount = FastMoney.of(0, "EUR"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "€"); }
Example #10
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 #11
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 #12
Source File: DefaultMonetaryAmountFormatTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testFormat() { AmountFormatContextBuilder builder = AmountFormatContextBuilder.of(US); AmountFormatContext context = builder.build(); DefaultMonetaryAmountFormat format = new DefaultMonetaryAmountFormat(context); String formatted = format.format(FastMoney.of(1000.42, "USD")); assertEquals(formatted, "USD1,000.42"); }
Example #13
Source File: Mock.java From javamoney-examples with Apache License 2.0 | 5 votes |
public static List<Product> hello(CurrencyUnit unit) { List<Product> products = new ArrayList<>(); products.add(new Product("Banana", FastMoney.of(20, unit))); products.add(new Product("DVD", FastMoney.of(50, unit))); products.add(new Product("CD", FastMoney.of(5, unit))); products.add(new Product("Computer", FastMoney.of(999.9, unit))); products.add(new Product("Notebook", FastMoney.of(2500.69, unit))); products.add(new Product("Phone", FastMoney.of(800, unit))); products.add(new Product("Memory", FastMoney.of(189, unit))); products.add(new Product("Table", FastMoney.of(240, unit))); products.add(new Product("Blu-ray", FastMoney.of(60, unit))); products.add(new Product("Camera", FastMoney.of(560, unit))); return products; }
Example #14
Source File: MoneyUtilsTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testCheckAmountParameter() { CurrencyUnit dollar = Monetary.getCurrency("USD"); CurrencyUnit real = Monetary.getCurrency("BRL"); checkAmountParameter(FastMoney.of(0, "USD"), dollar); expectThrows(MonetaryException.class, () -> checkAmountParameter(FastMoney.of(0, "USD"), real)); }
Example #15
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 #16
Source File: DefaultMonetaryAmountFormatTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testFormat_with_two_patterns_without_currency() { AmountFormatContextBuilder builder = AmountFormatContextBuilder.of(US); builder.set("pattern", "0.00;0.0"); AmountFormatContext context = builder.build(); DefaultMonetaryAmountFormat format = new DefaultMonetaryAmountFormat(context); String formatted = format.format(FastMoney.of(1000.42, "USD")); assertEquals(formatted, "1000.42"); formatted = format.format(FastMoney.of(-1000.42, "USD")); assertEquals(formatted, "-1000.4"); }
Example #17
Source File: DefaultMonetaryAmountFormatTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testFormat_with_two_patterns() { AmountFormatContextBuilder builder = AmountFormatContextBuilder.of(US); builder.set("pattern", "0.00 ¤;0.0 ¤"); AmountFormatContext context = builder.build(); DefaultMonetaryAmountFormat format = new DefaultMonetaryAmountFormat(context); String formatted = format.format(FastMoney.of(1000.42, "USD")); assertEquals(formatted, "1000.42 USD"); formatted = format.format(FastMoney.of(-1000.42, "USD")); assertEquals(formatted, "-1000.4 USD"); }
Example #18
Source File: DefaultMonetaryAmountFormatTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testFormat_with_custom_pattern() { AmountFormatContextBuilder builder = AmountFormatContextBuilder.of(US); builder.set("pattern", "0.00 ¤"); AmountFormatContext context = builder.build(); DefaultMonetaryAmountFormat format = new DefaultMonetaryAmountFormat(context); String formatted = format.format(FastMoney.of(1000.42, "USD")); assertEquals(formatted, "1000.42 USD"); }
Example #19
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_SYMBOL_BTC() throws IOException { CurrencyToken token = new CurrencyToken(SYMBOL, AmountFormatContextBuilder.of(FRANCE).build()); FastMoney amount = FastMoney.of(0, BTC); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "BTC"); // returned currency code itself }
Example #20
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 #21
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 #22
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 #23
Source File: CreateMonetaryCurrency.java From javamoney-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) { CurrencyUnit real = Monetary.getCurrency("BRL"); CurrencyUnit dollar = Monetary.getCurrency(Locale.US); MonetaryAmount money = Money.of(120, real); MonetaryAmount fastMoney = FastMoney.of(80, dollar); System.out.println(money); System.out.println(fastMoney); }
Example #24
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_SYMBOL_UAH_for_US() throws IOException { CurrencyToken token = new CurrencyToken(SYMBOL, AmountFormatContextBuilder.of(US).build()); FastMoney amount = FastMoney.of(0, "UAH"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "UAH"); }
Example #25
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_SYMBOL_UAH() throws IOException { CurrencyToken token = new CurrencyToken(SYMBOL, AmountFormatContextBuilder.of(new Locale("uk", "UA")).build()); FastMoney amount = FastMoney.of(0, "UAH"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "₴"); }
Example #26
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_SYMBOL_HKD_for_US() throws IOException { CurrencyToken token = new CurrencyToken(SYMBOL, AmountFormatContextBuilder.of(US).build()); FastMoney amount = FastMoney.of(0, "HKD"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "HK$"); }
Example #27
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 #28
Source File: CurrencyTokenTest.java From jsr354-ri with Apache License 2.0 | 5 votes |
@Test public void testPrint_SYMBOL_USD_for_France() throws IOException { CurrencyToken token = new CurrencyToken(SYMBOL, AmountFormatContextBuilder.of(FRANCE).build()); FastMoney amount = FastMoney.of(0, "USD"); StringBuilder sb = new StringBuilder(); token.print(sb, amount); assertEquals(sb.toString(), "$US"); }
Example #29
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 #30
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"); }