Java Math - rint() Method
The Java rint() method returns the double value that is closest to the argument and equal to a mathematical integer. In special cases it returns the following:
- If the argument value is already equal to a mathematical integer, then the result is the same as the argument.
- If the argument is NaN or an infinity or positive zero or negative zero, then the result is the same as the argument.
Syntax
public static double rint(double arg)
Parameters
arg |
Specify a double value. |
Return Value
Returns the double value that is closest to the argument and equal to a mathematical integer.
Exception
NA.
Example:
In the example below, rint() method returns the double value that is closest to the given argument and equal to a mathematical integer.
public class MyClass { public static void main(String[] args) { System.out.println(Math.rint(48.45)); System.out.println(Math.rint(48.55)); } }
The output of the above code will be:
48.0 49.0
❮ Java Math Methods