Search code examples
javalocaledecimalformat

Different Formats between java8 and java12


With Java8 the following code worked fine. Now i want to upgrade to java12 i've got the problem, that this will not work.

  public static void main(String[] args) {
    Double d = new Double(123456.8912);
    Locale locale = new Locale.Builder().setLanguage("de").setRegion("AT").build();

    DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(locale);
    decimalFormat.applyLocalizedPattern("#.##0,00");

    System.out.println(decimalFormat.format(d.doubleValue()));
    // Excpected is 123.456,89
    // Output is 123456,89.
  }

Solution

  • The problem is not a java one. Seems to be a bug in CLDR. Austria differ from Germany, but should not.

    (http://openjdk.java.net/jeps/252) Java used data from CLDR.

    With the parameter -Djava.locale.providers=COMPAT,SPI set it will act like java8.

    I will open a ticket at CLDR for this problem.