Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2033422 | 1.4.0 | Norbert Lindenberg | P4 | Resolved | Fixed | beta |
Name: skT45625 Date: 04/13/2000
java version "1.3.0rc2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc2-Y)
Java HotSpot(TM) Client VM (build 1.3.0rc2-Y, mixed mode)
Using engineering notation such as ##0.#E0 with numbers less than 1 often gives
incorrect results.
This program:
import java.text.*;
public class DecForm {
public static void main(String args[]) {
test(0.05);
test(0.005);
test(0.0005);
}
static void test(double d) {
test(d, "000.#E0");
test(d, "##0.#E0");
test(d, "#00.#E0");
System.out.println();
}
static void test(double d, String f) {
DecimalFormat df = new DecimalFormat(f);
System.out.print(f + " " + df.format(d) + " ");
}
}
Produces the output:
000.#E0 500E-4 ##0.#E0 5E-3 #00.#E0 50E-3
000.#E0 500E-5 ##0.#E0 5E-3 #00.#E0 5.0E-3
000.#E0 500E-6 ##0.#E0 5E-6 #00.#E0 50E-6
The last line of output says that 500E-6 = 5E-6 = 50E-6. Clearly, these results
are incorrect.
(Review ID: 103664)
======================================================================
- backported by
-
JDK-2033422 DecimalFormat engineering notation gives incorrect results
-
- Resolved
-