Why does Math.round(0.49999999999999994) return 1?
In the following program you can see that each value slightly less than .5 is rounded down, except for 0.5. for (int i = 10; i >= 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) … Read more