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

Wrong formatting in java.text.NumberFormat class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.2
    • core-libs
    • sparc
    • solaris_2.6



      Name: dbT83986 Date: 11/14/99


      java version "1.2.2"
      Classic VM (build JDK-1.2.2-W, green threads, sunwjit)



      P.1
      [cms2] ~/work/Monarc/investigations/scripts > javac Test.java
      [cms2] ~/work/Monarc/investigations/scripts > java Test

      P.2
      Test.java source code:
      import java.text.NumberFormat;

      public class Test{
      // Main method
              public static void main(String args[]) {
                      Test test=new Test(0);
                      double x[] = { 6.0,0.0 };
                      for(int i=0;i<x.length;i++) test.formatNum(x[i]);
                      System.exit(0);
              }

      // Test class
              public NumberFormat numberFormat;
              public int numfracdigits;

              public Test(int numfracdigits){
                      this.numfracdigits = numfracdigits;
                      numberFormat = NumberFormat.getInstance() ;
          numberFormat.setMinimumFractionDigits(this.numfracdigits);
          numberFormat.setMaximumFractionDigits(this.numfracdigits);
              };

        public void formatNum(double num) {
      // Uncommenting these lines gives valid result
      // numberFormat = NumberFormat.getInstance();
      // numberFormat.setMinimumFractionDigits(numfracdigits);
      // numberFormat.setMaximumFractionDigits(numfracdigits);
                      String outnum = numberFormat.format(num);
                      System.out.println("Number:"+num+" Formatted:"+outnum);
        }

      }

      P.3 This is output:

      Number:6.0 Formatted:6
      Number:0.0 Formatted:1
      (Review ID: 97829)
      ======================================================================

            nlindenbsunw Norbert Lindenberg (Inactive)
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: