JDK-4147706 : java.text.DecimalFormat.format(double d) incorrectly works with -0.0
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.2.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5
  • CPU: sparc
  • Submitted: 1998-06-11
  • Updated: 1999-01-14
  • Resolved: 1998-07-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.2.0 1.2fcsFixed
Related Reports
Relates :  
Description

Name: dfC67450			Date: 06/11/98



The java.text.DecimalFormat.format(double d) treats -0.0 as the positive number.
But following the principles of float and double type -0.0 and +0.0 are the 
different numbers and should be processed in the differnt ways. Javadoc should 
clarify it.

Here is the test demonstrating the bug:

-----------------TestD.java------------------------
import java.text.*;
import java.util.*;


public class TestD {

    public static void main (String args[]){
        DecimalFormat df = new DecimalFormat("#,##0.0##");
        df.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH));
        double d1 = -0.0;
        double d2 = -0.0001;
        StringBuffer f1 = df.format(d1, new StringBuffer(), new FieldPosition(0));
        StringBuffer f2 = df.format(d2, new StringBuffer(), new FieldPosition(0));
        if ( !f1.equals("-0.0") || !f2.equals("-0.0")) {
          System.out.println("Test failed");
          System.out.println("pattern: \"" + df.toPattern() + "\"");
          System.out.println(d1 + "      is formatted as " + f1);
          System.out.println(d2 + "      is formatted as " + f2);
          System.out.println("This numbers should be formatted as -0.0");
        } else {
          System.out.println("Test passed");
        }
    }
} 
---------Output from the test---------------------
Test failed
pattern: "#,##0.0##"
-0.0      is formatted as 0.0
-1.0E-4      is formatted as 0.0
This numbers should be formatted as -0.0
--------------------------------------------------

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

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: generic FIXED IN: 1.2fcs INTEGRATED IN: 1.2fcs VERIFIED IN: 1.2fcs
14-06-2004

EVALUATION This bug is related to older bugs 4106658 and 4106667, which were never really handled correctly. The bug has to do with the handling of the special value -0.0, which is a zero with a negative sign big. IEEE numerics requires this value to be recognized as a distinct entity from +0.0; we have been formatting it as if they were the same. Two one-line changes to DecimalFormat, and correction of the regression test NumberRegression, fix this problem.
11-06-2004