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

Decimal format with positive suffix breaks after formatting zero

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows

      Description

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

      ADDITIONAL OS VERSION INFORMATION :
      Windows 10 Pro, v1709, OS Build 16299.64

      A DESCRIPTION OF THE PROBLEM :
      When using a DecimalFormat with a positive suffix, the format method returns correctly until the first time the value 0.0 is passed. At this point, the decimal separator is removed and replaced by the first character of the specified suffix. The cause is down to how the fastFormat data is handled. When 0.0 is passed, the decimal separator is overwritten with the suffix in the FastPathData instance, and is never re-introduced later.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a new NumberFormat instance by calling the NumberFormat.getInstance() method (Other constructors can be used, so long as the resulting instance matches the fast formatting rules in the DecimalFormat class).

      Cast the instance to a DecimalFormat instance, and set the positive suffix to a non empty string, e.g. "ft".

      Call format on a fractional value greater than one, e.g. 1.5 and display the result.

      Call format on passing zero and display the result.

      Call format on a fractional value greater than one, e.g. 1.5 and display the result.




      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The expected output is;

      1.5ft
      0ft
      1.5ft
      ACTUAL -
      The actual result is;
      1.5ft
      0ft
      1f5ft

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      NumberFormat format = NumberFormat.getInstance();
      ((DecimalFormat) format).setPositiveSuffix("ft");
      System.out.println(format.format(1.5));
      System.out.println(format.format(0.0));
      System.out.println(format.format(1.5));
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None found.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psonal Pallavi Sonal (Inactive)
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: