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

[Fmt-Nu] API: Number format anomaly for Indian(English) Locale

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs
    • generic, x86
    • generic, windows_xp



      Name: dk106046 Date: 02/20/2004

      When I execute the testcase below under on any JDK...
      ------------------------------------------------------------------------------------
      public class Test2{
            public static void main(String aa[]){
      try
      { Locale indLoca = new Locale("en", "IN");
      NumberFormat nf = NumberFormat.getNumberInstance(indLoca);
      String s = NumberFormat.getNumberInstance(indLoca).format(99999999);
      System.out.println(s);
      } catch (Exception e)
      {
      }
      }
       }
      ------------------------------------------------------------------------------------

      the ouput comes as
         99,999,999

      while the expected output for the Indian Locale is
         9,99,99,999

      which does not complie with the Standard Indian(English) number format as specified above.

      Some additional observations:

      I have found out the method which actually sets the number of grouping characters defined in the java file java.text.DecimalFormat.java
          public void setGroupingSeparator(char groupingSeparator) {
              this.groupingSeparator = groupingSeparator;
           }
         
      This function takes only one parameter and therefore, we can have only one particular size separators. For the Indian locale, we essentially require the first separator to be after 3 digits and after that they should occur in spaces of 2 digits.

      Here are some comments from the java.text.DecimalFormat.java:

      The grouping separator is commonly used for thousands, but in some countries it separates ten-thousands. The grouping size is a constant number of digits between the grouping characters, such as 3 for 100,000,000 or 4 for 1,0000,0000. If you supply a pattern with multiple grouping characters, the interval between the last one and the end of the integer is the one that is used. So <code>"#,##,###,####"</code> == <code>"######,####"</code> == * <code>"##,####,####"</code>.

      Therefore, any change for a fix, would mean a change to the API.

      ======================================================================

            peytoia Yuka Kamiya (Inactive)
            dkorbel David Korbel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: