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

DecimalFormat with rounding mode regression defect

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 8
    • core-libs
    • x86_64
    • windows_7

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

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      DecimalFormat rounding is broken

      REGRESSION. Last worked in version 7u51

      ADDITIONAL REGRESSION INFORMATION:
      Broken using:
      java version "1.8.0"
      Java(TM) SE Runtime Environment (build 1.8.0-b132)
      Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)

      Works using:
      java version "1.7.0_17"
      Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
      Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      public class Test {

      public static void main(String[] args) {
      DecimalFormat df = new DecimalFormat("#.00");
      df.setRoundingMode(RoundingMode.HALF_UP);
      final String s = df.format(12.465d);
      if (s.equals("12.47")) {
      System.out.println("All is right with the world");
      } else {
      throw new RuntimeException("Rounding is broken in Java " + System.getProperty("java.version"));
      }
      }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      "All is right with the world"

      ACTUAL -
      Exception in thread "main" java.lang.RuntimeException: Rounding is broken in Java 1.8.0
      at Test.main(Test.java:32)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.math.RoundingMode;
      import java.text.DecimalFormat;


      public class Test {

      public static void main(String[] args) {
      DecimalFormat df = new DecimalFormat("#.00");
      df.setRoundingMode(RoundingMode.HALF_UP);
      final String s = df.format(12.465d);
      if (s.equals("12.47")) {
      System.out.println("All is right with the world");
      } else {
      throw new RuntimeException("Rounding is broken in Java " + System.getProperty("java.version"));
      }
      }
      }

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

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: