+ 1

Math.rint

Can anybody explain why Math.rint(11.5) vs Math.rint(12.5) have the same result?

18th Jun 2017, 3:09 PM
sadco
sadco - avatar
3 Answers
+ 4
When 2 numbers are of equal distance (x.5) the result will be the even number. So 11.5 rounds to 12. Since 12 is even, 11 is not. 12.5 rounds to 12, Since 12 is even, 13 is not.
18th Jun 2017, 6:27 PM
Rrestoring faith
Rrestoring faith - avatar
+ 2
Just when it comes to the .5, round() will round up in this case.
18th Jun 2017, 7:20 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
thanks, I thought Math.rint is pretty much the same thing as Math.round.
18th Jun 2017, 6:51 PM
sadco
sadco - avatar