When I am using Math.rint() function in JAVA,the output was coming different for 8.5 .Since Math.rint() function returns greatest double value but in the case of 8.5 it is returnig 8.0 whereas for other number like 7.5 and 9.5 ,it is returning 8.0 and 10.0 respectively.I have attached program and ouput screenshot .Please help if you can. This is the Program and output
Asked
Active
Viewed 1,134 times
1
-
Why do you ask this question a second time? (https://stackoverflow.com/questions/65272249/why-output-is-coming-different-for-8-5-while-using-math-rint-in-java) – Tom Dec 17 '20 at 02:54
1 Answers
1
If two double values that are mathematical integers are equally close, this method will return integer value that is even.
So for 8.5 the nearest value can be 8.0 or 9.0(as they both are equally close), and according to above statement it will try to make it a even number.

lakshya
- 129
- 1
- 3