Java StrictMath - rint() Method
The java.lang.StrictMath.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 a)
Parameters
a |
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.
import java.lang.*; public class MyClass { public static void main(String[] args) { System.out.println(StrictMath.rint(48.45)); System.out.println(StrictMath.rint(48.55)); } }
The output of the above code will be:
48.0 49.0
❮ Java.lang - StrictMath