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

A space as a group separator for localized pattern causes wrong format

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • 1.2.0
    • core-libs
    • sparc
    • solaris_2.5

      import java.text.NumberFormat;
      import java.text.DecimalFormat;
      import java.util.Locale;
      import java.text.ParseException;

      class Main {

          public static void main(String[] args) {

              
      NumberFormat nf = NumberFormat.getInstance(Locale.FRANCE);
      System.out.println("nf toPattern1: " + ((DecimalFormat)nf).toPattern());
      System.out.println("nf toLocPattern1: " + ((DecimalFormat)nf).toLocalizedPattern());

         // No group separator

              System.out.println("\n...applyLocalizedPattern ###,00;(###,00) ");
      ((DecimalFormat)nf).applyLocalizedPattern("###,00;(###,00)");
      System.out.println("nf toPattern2: " + ((DecimalFormat)nf).toPattern());
      System.out.println("nf toLocPattern2: " + ((DecimalFormat)nf).toLocalizedPattern());

      System.out.println("nf: " + nf.format(1234)); // 1234,00
      System.out.println("nf: " + nf.format(-1234)); // (1234,00)

         // Space as group separator

              System.out.println("\n...applyLocalizedPattern # ###,00;(# ###,00) ");
      ((DecimalFormat)nf).applyLocalizedPattern("# ###,00;(# ###,00)");
      System.out.println("nf toPattern2: " + ((DecimalFormat)nf).toPattern());
      System.out.println("nf toLocPattern2: " + ((DecimalFormat)nf).toLocalizedPattern());

      System.out.println("nf: " + nf.format(1234)); // Expect 1 234,00
      System.out.println("nf: " + nf.format(-1234)); // Expect (1 234,00)

      // Erroneously prints:
      // 1234,00 ,
      // (1234,00 ,)

          }
      }

      Output is:

      % javac Main1.java
                                                                                                                       [doog]/home/dkramer/tmp % java Main1
      nf toPattern1: #,##0.###
      nf toLocPattern1: # ##0,###
       
      ...applyLocalizedPattern ###,00;(###,00)
      nf toPattern2: #.00;(#.00)
      nf toLocPattern2: #,00;(#,00)
      nf: 1234,00
      nf: (1234,00)
       
      ...applyLocalizedPattern # ###,00;(# ###,00)
      nf toPattern2: #.00### ,;(#.00### ,)
      nf toLocPattern2: #,00### ,;(#,00### ,)
      nf: 1234,00 ,
      nf: (1234,00 ,)

      I believe the separators for the last give lines should look like:

      ...applyLocalizedPattern # ###,00;(# ###,00)
      nf toPattern2: # ###,00;(# ###,00)
      nf toLocPattern2: # ###,00;(# ###,00)
      nf: 1 234,00
      nf: (1 234,00)

            joconnersunw John Oconner (Inactive)
            dkramersunw Douglas Kramer (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: