I noticed an incomprehensible thing for me in static method round() in class Math:
Math.round(0.4999999999999999); // is 0
Math.round(0.49999999999999999); // is 1
Why?
I noticed an incomprehensible thing for me in static method round() in class Math:
Math.round(0.4999999999999999); // is 0
Math.round(0.49999999999999999); // is 1
Why?
0.49999999999999999
has too many significant digits and one double
variable cannot store them all. So implicit rounding happens during compilation. By the time you are calling Math.round()
, the argument is already 0.5 (check yourself: 0.49999999999999999 == 0.5
yields true
).