title: Why does Math.round(0.49999999999999994) return 1?
body: <p>In the following program you can see that each value slightly less than <code>.5</code> is rounded down, except for <code>0.5</code>.</p>
  
  <pre><code>for (int i = 10; i &gt;= 0; i--) {
      long l = Double.doubleToLongBits(i + 0.5);
      double x;
      do {
          x = Double.longBitsToDouble(l);
          System.out.println(x + " rounded is " + Math.round(x));
          l--;
      } while (Math.round(x) &gt; i);
  }
  </code></pre>
  
  <p>prints</p>
  
  <pre><code>10.5 rounded is 11
  10.499999999999998 rounded is 10
  9.5 rounded is 10
  9.499999999999998 rounded is 9
  8.5 rounded is 9
  8.499999999999998 rounded is 8
  7.5 rounded is 8
  7.499999999999999 rounded is 7
  6.5 rounded is 7
  6.499999999999999 rounded is 6
  5.5 rounded is 6
  5.499999999999999 rounded is 5
  4.5 rounded is 5
  4.499999999999999 rounded is 4
  3.5 rounded is 4
  3.4999999999999996 rounded is 3
  2.5 rounded is 3
  2.4999999999999996 rounded is 2
  1.5 rounded is 2
  1.4999999999999998 rounded is 1
  0.5 rounded is 1
  0.49999999999999994 rounded is 1
  0.4999999999999999 rounded is 0
  </code></pre>
  
  <p>I am using Java 6 update 31.</p>