Summary
DecimalFormat uses a double->string algorithm that was used in releases prior to JDK 21. Meanwhile, Formatter and Double.toString() use a newer algorithm introduced in JDK 21. In very rare cases, this leads to slightly different outcomes between DecimalFormat and Formatter with equivalent format specifications when formatting doubles.
Problem
In rare cases, DecimalFormat and Formatter produce slightly different outcomes on some doubles.
For example, currently the double
7.3879E20 is output as "738790000000000100000" with DecimalFormat and as "738790000000000000000" with Formatter, given equivalent format specifications.
With this change, the outcomes are the same.
Solution
By using the same algorithm used by Double.toString() and Formatter, the behavior of DecimalFormat becomes aligned with these and produce comparable outcomes.
Specification
There are no visible API changes. This is a behavioral change on those rare doubles that the old double->string algorithm converts slightly differently than the new algorithm.
To help migrating applications that might be impacted by this change, for a few releases the old algorithm will still be available to DecimalFormat and classes that depend on it.
The old algorithm can be enabled with the "-Djdk.compat.DecimalFormat=true" option on the launcher command line. Absent this option, the new algorithm is used.
- csr of
-
JDK-8362448 Make use of the Double.toString(double) algorithm in java.text.DecimalFormat
-
- In Progress
-