Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8362448

Make use of the Double.toString(double) algorithm in java.text.DecimalFormat

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • 26
    • None
    • core-libs
    • In Review
    • 21

      Currently, DecimalFormat sometimes outputs `double`s with more digits than the equivalent outputs of Formatter, or with slightly different digits.
      For example, the `double` 7.3879E20 is output as "738790000000000100000" with DecimalFormat and as "738790000000000000000" with Formatter, given equivalent format specifications.

      Since JDK 21, Double.toString() and Formatter use a new double->string algorithm, while DecimalFormat still uses the original double->string algorithm from older releases.
      The consequence is that the outcomes of DecimalFormat and Formatter may differ even with equivalent format specifications.

      While this mismatch rarely happens in practice (the vast majority of doubles work just fine), it is preferable to align DecimalFormat with Formatter, and make use of the new double->string algorithm introduced in JDK 21 in DecimalFormat as well.

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

              Created:
              Updated: