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

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

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 8u25
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_xp

      Description

      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

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: