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

RoundingMode.HALF_UP gives different results with NumberFormat

XMLWordPrintable

    • x86_64
    • linux_ubuntu

      A DESCRIPTION OF THE PROBLEM :
      RoundingMode.HALF_UP gives different results with NumberFormat

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the provided code. You will see the following output:

      0.675 -> 0.68
      12345.675 -> 12,345.67

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      0.675 -> 0.68
      12345.675 -> 12,345.68

      ---------- BEGIN SOURCE ----------
      NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
      numberFormat.setMaximumFractionDigits(2);
      numberFormat.setMinimumFractionDigits(2);
      numberFormat.setRoundingMode(RoundingMode.HALF_UP);

      System.out.println("0.675 -> " + numberFormat.format(0.675));
      System.out.println("12345.675 -> " + numberFormat.format(12345.675));
      ---------- END SOURCE ----------

      FREQUENCY : always


            naoto Naoto Sato
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: