Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8300869 Make use of the Double.toString(double) algorithm in java.util.Formatter
  3. JDK-8301383

Release Note: `java.util.Formatter` May Return Slightly Different Results on `double` and `float`

XMLWordPrintable

    • Icon: Sub-task Sub-task
    • Resolution: Delivered
    • Icon: P4 P4
    • 21
    • 21
    • core-libs
    • In Review
    • generic
    • generic

      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"`.

            rgiulietti Raffaello Giulietti
            rgiulietti Raffaello Giulietti
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: