+ 7

What is the difference between Math.rint() method and Math.round() method ?

Math.round(2.5)=3.0 but Math.rint(2.5)=2.0

9th May 2017, 12:54 PM
Pratham
Pratham - avatar
2 Answers
+ 1
java.lang.Math.rint(double a) returns the double value that is closest in value to the argument and is equal to a mathematical integer. If two double values that are mathematical integers are equally close, the result is the integer value that is even. Math.round will round up 1/2 regardless of the number, rint will only round up odd 'halves'
9th May 2017, 1:04 PM
botheredbybees
botheredbybees - avatar