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

double accumulation error

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      19 sets of double type values add jvm cash


      ---------- BEGIN SOURCE ----------
      import java.math.BigDecimal;
      import java.util.Random;

      public class TestDoubleError {

          public static void main(String[] args) {
              TestDoubleError a = new TestDoubleError();
              for (int i = 0; i < 100000; i++) {
                  String executer = a.executer("test-" + i);
                  System.out.println(executer);
              }
              System.out.println("run-end");
          }

          public String executer(String uuid) {
              System.out.println("run" + uuid);

              double totalScore = 0;
              String realDetailStr = "";

              try {
                  Random rd = new Random();
                  totalScore = totalScore + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0;

      // System.out.println(totalScore);
                  BigDecimal bigDecimal = new BigDecimal(totalScore).setScale(2, BigDecimal.ROUND_HALF_UP);
                  totalScore = bigDecimal.doubleValue();

              } catch (Exception e) {
              }
              return totalScore + "," + realDetailStr;
          }

      }
      ---------- END SOURCE ----------

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: