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

Rounding error in NumberFormat

    Details

    • Subcomponent:
    • Introduced In Version:
      8
    • CPU:
      generic
    • OS:
      generic

      Description

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

      ADDITIONAL OS VERSION INFORMATION :
      CentOS release 5.3 (Final)

      A DESCRIPTION OF THE PROBLEM :
      The following code is supposed to print "1.235". In stead, it prints "1.234"

      NumberFormat nf = NumberFormat.getInstance();
      nf.setRoundingMode(RoundingMode.HALF_UP);
      nf.setMaximumFractionDigits(3);
      System.out.println(nf.format(1.2345));


      REGRESSION. Last worked in version 7u80

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_72"
      Java(TM) SE Runtime Environment (build 1.8.0_72-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 25.72-b15, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code in description field


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      NumberFormat nf = NumberFormat.getInstance();
      nf.setRoundingMode(RoundingMode.HALF_UP);
      nf.setMaximumFractionDigits(3);
      System.out.println(nf.format(1.2345));

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                ndcosta Nelson Dcosta (Inactive)
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: