-
Bug
-
Resolution: Fixed
-
P3
-
1.2.0
-
1.2fcs
-
sparc
-
solaris_2.5
-
Verified
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
--------------------------------------------------
======================================================================
- relates to
-
JDK-4101481 java.text.DecimalFormat.applyPattern doesn't set minimum integer digits
-
- Closed
-