This simple program demonstrates the bug:
Double amount = new Double(123456.78);
NumberFormat formatter = NumberFormat.getCurrencyInstance(locale);
String formatted = formatter.format(amount);
System.out.println(formatted);
formatter.setParseIntegerOnly(true);
System.out.println(formatter.parse(formatted));
The program gets a currency formatter for the given locale, formats the given amount with it, prints it out, and then attempts to parse the amount's integer portion only.
If I use the "en-US" locale, the formatted output is "$123,456.78", and the parsed integer portion is "123456", as expected.
With the "de-DE" locale, the formatted output is "123.456,78 DM", but the parse operation fails with this exception:
Exception in thread "main" java.text.ParseException: Unparseable number: "123.456,78 DM"
at java.text.NumberFormat.parse(NumberFormat.java:284)
at CurrencyCode.main(CurrencyCode.java:35)
I also get a ParseException when using the "fr-FR" locale:
Exception in thread "main" java.text.ParseException: Unparseable number: "123?456,78 F"
at java.text.NumberFormat.parse(NumberFormat.java:284)
at CurrencyCode.main(CurrencyCode.java:35)
The parse operation does seem to work for the "es-ES" locale, though.
Double amount = new Double(123456.78);
NumberFormat formatter = NumberFormat.getCurrencyInstance(locale);
String formatted = formatter.format(amount);
System.out.println(formatted);
formatter.setParseIntegerOnly(true);
System.out.println(formatter.parse(formatted));
The program gets a currency formatter for the given locale, formats the given amount with it, prints it out, and then attempts to parse the amount's integer portion only.
If I use the "en-US" locale, the formatted output is "$123,456.78", and the parsed integer portion is "123456", as expected.
With the "de-DE" locale, the formatted output is "123.456,78 DM", but the parse operation fails with this exception:
Exception in thread "main" java.text.ParseException: Unparseable number: "123.456,78 DM"
at java.text.NumberFormat.parse(NumberFormat.java:284)
at CurrencyCode.main(CurrencyCode.java:35)
I also get a ParseException when using the "fr-FR" locale:
Exception in thread "main" java.text.ParseException: Unparseable number: "123?456,78 F"
at java.text.NumberFormat.parse(NumberFormat.java:284)
at CurrencyCode.main(CurrencyCode.java:35)
The parse operation does seem to work for the "es-ES" locale, though.
- duplicates
-
JDK-8333755 NumberFormat integer only parsing breaks when format has suffix
-
- Closed
-
-
JDK-4709840 [Fmt-Nu] Fail to parse integer portion of currency formatted in de_DE locale
-
- Closed
-