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

java.text.DecimalFormat.format() loses precision

XMLWordPrintable

    • sparc
    • solaris_2.5



      Name: dfC67450 Date: 11/04/97



      java.text.DecimalFormat.format(double n, StringBuffer str, FieldPosition fp) incorrectly
      uses internal representation of double.
      See similar bug #4054318.
       
      Here is the test demonstrating the bug:

      -----------------Test.java------------------------
      import java.text.*;
      import java.math.*;
      public class Test {
          public static void main (String args[]){
              DecimalFormat df = new DecimalFormat();
              df.setMinimumFractionDigits(10);
              df.setGroupingUsed(false);
              double d = 1.000000000000001E7;
              BigDecimal bd = new BigDecimal(d);
              StringBuffer sb = new StringBuffer("");
              FieldPosition fp = new FieldPosition(0);
              System.out.println("d = " + d);
              System.out.println("BigDecimal.toString(): " + bd.toString());
              System.out.println("DecimalFormat.format(): " + df.format(d, sb, fp));
          }
      }

      ---------Output from the test---------------------
      d = 1.000000000000001E7
      BigDecimal.toString(): 10000000.00000000931322574615478515625
      DecimalFormat.format(): 10000000.0000000096
      --------------------------------------------------

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

            aliusunw Alan Liu (Inactive)
            dfazunensunw Dmitri Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: