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

java.text.DecimalFormat ROUND_UP formatting no longer works in Java 8

XMLWordPrintable

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

      FULL PRODUCT VERSION :
      java.text.DecimalFormat

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7

      A DESCRIPTION OF THE PROBLEM :
      The program below prints 576.34 instead of 576.35 as in Java 6

      import java.math.RoundingMode;
      import java.text.DecimalFormat;

      public class Main {

          public static void main(String[] args) {
              DecimalFormat amountFormatter = new DecimalFormat( "0.00" );

              Double d = 576.34700000;
              amountFormatter.setRoundingMode(RoundingMode.HALF_UP);
              String standardizedAmount = amountFormatter.format(d);
              System.out.println(standardizedAmount);

          }
      }

      REGRESSION. Last worked in version 6u43

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run program below
      import java.math.RoundingMode;
      import java.text.DecimalFormat;

      public class Main {

          public static void main(String[] args) {
              DecimalFormat amountFormatter = new DecimalFormat( "0.00" );

              Double d = 576.34700000;
              amountFormatter.setRoundingMode(RoundingMode.HALF_UP);
              String standardizedAmount = amountFormatter.format(d);
              System.out.println(standardizedAmount);

          }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      576.35
      ACTUAL -
      576.34

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      import java.math.RoundingMode;
      import java.text.DecimalFormat;

      public class Main {

          public static void main(String[] args) {
              DecimalFormat amountFormatter = new DecimalFormat( "0.00" );

              Double d = 576.34700000;
              amountFormatter.setRoundingMode(RoundingMode.HALF_UP);
              String standardizedAmount = amountFormatter.format(d);
              System.out.println(standardizedAmount);

          }
      }
      ---------- END SOURCE ----------

      SUPPORT :
      YES

            olagneau Olivier Lagneau (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: