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

NumberStringConverter and its siblings should respect the FORMAT locale

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • jfx12, 8u60
    • javafx
    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10, Java 12

      A DESCRIPTION OF THE PROBLEM :
      The default constructor of javafx.util.converter.NumberStringConverter use the default locale returned by Locale.getDefault(). If the format locale (returned by Locale.getDefault(Category.FORMAT)) is different formatting in the application is not consistent as E.g. a default NumberFormat uses the format locale as shown below in the default factory method:

          public final static NumberFormat getNumberInstance() {
              return getInstance(Locale.getDefault(Locale.Category.FORMAT), NUMBERSTYLE);
          }

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Set the format locale different from the default locale:
              Locale.setDefault(Locale.US);
              Locale.setDefault(Category.FORMAT, Locale.GERMANY);
      This will be the case when you have a English language Windows and set the regional formatting settings to something different.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Using a NumberFormat and a NumberStringConverter created with the default factory method/constructor should result in consistent formatting.
      ACTUAL -
      Using a NumberFormat and a NumberStringConverter created with the default factory method/constructor might result in different output for the same value.

      ---------- BEGIN SOURCE ----------
      import java.text.NumberFormat;
      import java.util.Locale;
      import java.util.Locale.Category;

      import javafx.util.converter.DoubleStringConverter;

      public class Test
      {

          public static void main(String[] args)
          {
              Locale.setDefault(Locale.US);
              Locale.setDefault(Category.FORMAT, Locale.GERMANY);

              System.out.println(NumberFormat.getInstance().format(1.234d));
              System.out.println(new DoubleStringConverter().toString(1.234d));
          }

      }

      ---------- END SOURCE ----------

            kcr Kevin Rushforth
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: