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

Wrong rounding with DecimalFormat

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      OSX, JDK 8 Update 212

      A DESCRIPTION OF THE PROBLEM :
      Wrong rounding of .0002755
       double v1 = .0002665d;
      System.out.println(new DecimalFormat("#.000000").format(v1));
      double v2 = .0002755d;
      System.out.println(new DecimalFormat("#.000000").format(v2));
      /* Result:
                  .000267
                  .000275
      */


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      double v2 = .0002755d;
      System.out.println(new DecimalFormat("#.000000").format(v2));

      double v2 = .0002755d;
      System.out.println(new DecimalFormat("#.######").format(v2));

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      .000276
      ACTUAL -
      .000275

      ---------- BEGIN SOURCE ----------
      double v2 = .0002755d;
      System.out.println(new DecimalFormat("#.000000").format(v2));
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      3rd party libs or use python

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            psonal Pallavi Sonal (Inactive)
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: