Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4630856

[Fmt-Nu] Fail to parse integer portion from de-DE and fr-FR currencies

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 24
    • 1.3.1
    • core-libs
    • None
    • b04
    • generic
    • generic
    • Verified

      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.

            jlu Justin Lu
            jlueheorcl Jan Luehe (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: