JDK-8301383 : Release Note: `java.util.Formatter` May Return Slightly Different Results on `double` and `float`
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 21
  • Priority: P4
  • Status: Resolved
  • Resolution: Delivered
  • OS: generic
  • CPU: generic
  • Submitted: 2023-01-30
  • Updated: 2023-07-28
  • Resolved: 2023-02-16
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.
JDK 21
21Resolved
Related Reports
Relates :  
Relates :  
Description
The implementation of `java.util.Formatter` for `double` and `float` conversions to decimal (`'e'`, `'E'`, `'f'`, `'g'`, `'G'`) is now aligned with the one in `Double.toString(double)`, which was changed in JDK 19.

As a consequence, in some rare circumstances, the outcomes may slightly differ from the ones in earlier releases.

One example is with `double` `2e23` and format `"%.16e"`. With this change, the outcome is `2.0000000000000000e+23`, while earlier releases produce `1.9999999999999998e+23`. Any smaller precision in the format (e.g., "%.15e") on this value will produce outcomes that are equal to each other, though.

Another example is with `double` `9.9e-324` and format `"%.2g"`. The new outcome is `9.9e-324`, but earlier releases generate `"1.0e-323"`.