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

DecimalFormat Half_UP rounding mode does not work properly

    Details

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

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      teh problem happens rounding a number using the DecimalFormat class using setRoundingMode method and formating. Teh result of this format using RoundigMode.HALF_UP results in a down rounding. The best way to describe the error is through an example.

      Using this code:

      DecimalFormat df = new DecimalFormat("#.00");
      df.setRoundingMode(RoundingMode.HALF_UP);
      String result = df.format(12.465d);

      In java 6 result is 12.47
      in java 8 result is 12.46

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The best way to describe the error is through an example.

      Using this code:

      DecimalFormat df = new DecimalFormat("#.00");
      df.setRoundingMode(RoundingMode.HALF_UP);
      String result = df.format(12.465d);


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      DecimalFormat df = new DecimalFormat("#.00");
      df.setRoundingMode(RoundingMode.HALF_UP);
      String result = df.format(12.465d);
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                peytoia Yuka Kamiya (Inactive)
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: