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

DecimalFormat does not use german grouping/decimal.

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      openjdk version "11.0.2" 2019-01-15
      OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
      OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)

      Using different LocaleProviders does not change the behaviour, i.e. -Djava.locale.providers=COMPAT instead of default.

      A DESCRIPTION OF THE PROBLEM :
      If you use DecimalFormat to format a double above 1000 with to decimals (12345.78) and german locale the outcome is like with en_US locale ("12,345.78"). Expected is german format like "12.345,78".

      REGRESSION : Last worked in version 8u201

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Instantiate DecimalFormat. The way doing it (getInstance or Constructor) does not change behaviour.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected is a formatted String of an double according to German formatting conventions as described in CLDR i.e. "12.345,78".
      ACTUAL -
      The String is formatted as en_US, i.e. "12,345.78"

      ---------- BEGIN SOURCE ----------

      import java.text.DecimalFormat;
      import java.text.DecimalFormatSymbols;
      import java.text.NumberFormat;
      import java.util.Locale;
      import java.util.ResourceBundle;

      public class DecimalFormatTest
      {
         private DecimalFormatTest()
         {
            // no instance
         }

         private static final double DOUBLE_TO_FORMAT = 12345.78;

         private static final String EXPECTED_GERMAN_1234578 = "12.345,78";
         private static final String EXPECTED_US_1234578 = "12,345.78";

         public static void main(final String[] args)
         {
            System.out.println(System.getProperty("java.locale.providers"));

            final Locale deDE = new Locale("de", "DE");
            final NumberFormat deFormat1 = NumberFormat.getInstance(deDE);

            final String deDoubleStr1 = deFormat1.format(DecimalFormatTest.DOUBLE_TO_FORMAT);
            System.out.println("DE: " + deDoubleStr1 + " should be " + DecimalFormatTest.EXPECTED_GERMAN_1234578);

            System.setProperty("java.locale.providers", "COMPAT");

            ResourceBundle.clearCache();

            final var deFormat2 = NumberFormat.getNumberInstance(Locale.GERMANY);
            final var deDoubleStr2 = deFormat2.format(DecimalFormatTest.DOUBLE_TO_FORMAT);
            System.out.println("DE: " + deDoubleStr2 + " should be " + DecimalFormatTest.EXPECTED_GERMAN_1234578);

            ResourceBundle.clearCache();

            final Locale locale = Locale.GERMANY;
            final var decFormatSymbolsDE = DecimalFormatSymbols.getInstance(locale);

            final DecimalFormat deFormat3 = new DecimalFormat("#,##0.00", decFormatSymbolsDE);
            final var deDoubleStr3 = deFormat3.format(DecimalFormatTest.DOUBLE_TO_FORMAT);
            System.out.println("DE: " + deDoubleStr3 + " should be " + DecimalFormatTest.EXPECTED_GERMAN_1234578);

            final var decFormatSymbolsUS = DecimalFormatSymbols.getInstance(Locale.US);
            final DecimalFormat usFormat = new DecimalFormat("#,##0.00", decFormatSymbolsUS);
            final var usDoubleStr = usFormat.format(Double.valueOf(DecimalFormatTest.DOUBLE_TO_FORMAT));
            System.out.println("US: " + usDoubleStr + " should be " + DecimalFormatTest.EXPECTED_US_1234578);

         }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: