javamoney-examples icon indicating copy to clipboard operation
javamoney-examples copied to clipboard

Formatting using SYMBOL throws an exception

Open abhishek2bommakanti opened this issue 9 years ago • 7 comments

Running the FormatExample class throws an exception when we try to run the US SYMBOL code:

Nov 04, 2015 11:46:45 AM org.javamoney.moneta.DefaultMonetaryContextFactory createMonetaryContextNonNullConfig INFO: Using custom MathContext: precision=256, roundingMode=HALF_EVEN Exception in thread "main" javax.money.MonetaryException: No MonetaryAmountFormat for AmountFormatQuery AmountFormatQuery ( {Query.formatName=SYMBOL, java.util.Locale=en_US}) at javax.money.spi.MonetaryFormatsSingletonSpi.getAmountFormat(MonetaryFormatsSingletonSpi.java:71) at javax.money.format.MonetaryFormats.getAmountFormat(MonetaryFormats.java:110) at org.javamoney.examples.console.functional.FormatExample.main(FormatExample.java:24)

abhishek2bommakanti avatar Nov 04 '15 19:11 abhishek2bommakanti

Which version of the JSR/Moneta did you use to reproduce that?

keilw avatar Nov 04 '15 19:11 keilw

With both 1.0.1-SNAPSHOT as well as 1.0.

abhishek2bommakanti avatar Nov 04 '15 19:11 abhishek2bommakanti

Thanks, that indicates, it wasn't already fixed in master/1.0.1-SNAPSHOT. We'll look into it, trying to reproduce and when the reason can be found address it in the 1.0.1 codebase. Once other pending issues with that are resolved, at least the RI and where necessary other modules will get a service pack.

keilw avatar Nov 04 '15 20:11 keilw

Ok, great. Thank you for the update.

abhishek2bommakanti avatar Nov 04 '15 20:11 abhishek2bommakanti

Any update on this? Is this a problem the Moneta implementation?

rschanafelt avatar May 10 '16 18:05 rschanafelt

I ran this code, and it's fine. I believe, it's already fixed.

        DecimalFormatSymbols symbols = new DecimalFormatSymbols();
        MonetaryAmountFormat fmt =
                MonetaryFormats.getAmountFormat (
                        AmountFormatQueryBuilder.of(Locale.US)
                                .set(symbols)
                                .build ());
        CurrencyUnit currencyUnit = Monetary.getCurrency(Locale.US);
        System.out.println(fmt.format(Money.of(10, currencyUnit)));

otaviojava avatar May 10 '16 22:05 otaviojava

This appears to still be a problem. Is there any other solution? Please see my stack overflow question:

http://stackoverflow.com/questions/42098171/how-to-format-monetaryamount-with-currency-symbol

axiopisty avatar Feb 07 '17 19:02 axiopisty