JDK-4090489 : java.text.DecimalFormat.format() loses precision
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.1.4
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5
  • CPU: sparc
  • Submitted: 1997-11-04
  • Updated: 1998-09-11
  • Resolved: 1998-09-11
Related Reports
Duplicate :  
Description

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
--------------------------------------------------

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

Comments
EVALUATION This was a bug at one time, but it can no longer be reproduced. It was probably fixed in the huge putback that Senthil and Norbert Schatz did in November. ###@###.### 1997-12-15 ========================= The bug isn't fixed. So I reopen it. vvs@russia 1998-06-18 This bug is essentially a duplicate of 4117447. That bug states that DecimalFormat uses double, and that a separate formatter based on BigDecimal is required. To do so is not difficult, however, it does require a significant API change (a new class), which has not been approved for 1.2. I am closing this as a duplicate of 4117447. alan.liu@eng 1998-09-11
11-09-1998