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

DecimalFormat suffix stomps decimal separator when fraction pattern is optional

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_144"
      Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
      Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.14393]

      A DESCRIPTION OF THE PROBLEM :
      DecimalFormat's fastPath doesn't reapply the decimal separator after stomping on it with the suffix.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a DecimalFormat with a suffix, e.g. "#,###.###':'"

      Use it to format a number that has no decimal component.

      Use it to format a number with a decimal component.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      128:
      0.03:
      0.03:
      true
      ACTUAL -
      128:
      0:03:
      0.03:
      true

      Note the colon in the decimal position of the second line.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.text.DecimalFormat;

      public class DecimalFormatBug
      {
          public static void main(String[] args) {
              String f = "#,###.###':'";
              DecimalFormat df1 = new DecimalFormat(f);
              DecimalFormat df2 = new DecimalFormat(f);
              System.out.println(df1.format(128.0));
              System.out.println(df1.format(0.03));
              System.out.println(df2.format(0.03));
              System.out.println(df1.equals(df2));
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Don't use a suffix in the DecimalFormat or require a fractional digit, e.g. "#,###.0##':'";


      Attachments

        Issue Links

          Activity

            People

              rpatil Ramanand Patil (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: