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

DecimalFormat Half_UP rounding mode does not work properly

XMLWordPrintable

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

      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 ----------

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

              Created:
              Updated:
              Resolved: