KnowledgeBoat Logo

Computer Applications

Distinguish between Math.rint() and Math.round()

Java Math Lib Methods

129 Likes

Answer

Math.rint( )Math.round( )
Rounds off its argument to the nearest mathematical integer and returns its value as a double type.Rounds off its argument to the nearest mathematical integer and returns its value as an int or long type. If argument is float, return type is int, if argument is double, return type is long.
At mid-point, it returns the integer that is evenAt mid-point, it returns the higher integer.
double a = Math.rint(1.5);
double b =Math.rint(2.5);
Both, a and b will have a value of 2.0
long a = Math.round(1.5);
long b = Math.round(2.5);
a will have a value of 2 and b will have a value of 3

Answered By

81 Likes


Related Questions