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

java.text.DecimalFormat.format() fails when zeroDigit is not set to 0

XMLWordPrintable

    • sparc
    • solaris_2.5



      Name: dfC67450 Date: 10/29/97



      java.text.DecimalFormat.format(long n, StringBuffer str, FieldPosition fp) formats
      wrong if zeroDigit field of DecimalFormatSymbols field is not set to 0.
       
      Here is the test demonstrating the bug:

      -----------------Test.java------------------------
      import java.text.*;

      public class Test {
          public static void main (String args[]){
              DecimalFormat df = new DecimalFormat();
              DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
              dfs.setZeroDigit('z');
              df.setDecimalFormatSymbols(dfs);
              StringBuffer sBuf = new StringBuffer("");
              FieldPosition fp = new FieldPosition(0);
              System.out.println(df.format(1234567890, sBuf, fp));
              dfs.setZeroDigit('0');
              df.setDecimalFormatSymbols(dfs);
              sBuf = new StringBuffer("");
              fp = new FieldPosition(0);
              System.out.println(df.format(1234567890, sBuf, fp));
          }
      }
      ---------Output from the test---------------------
      {,|}~,,z
      1,234,567,890
      --------------------------------------------------

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

            joconnersunw John Oconner (Inactive)
            dfazunensunw Dmitri Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: