Java Math rint() Method
The rint() method of Java Math class returns the double value which is close to the specified argument and is equal to mathematical integer.
Syntax:
public static double rint(double a)
Parameters:
The parameter ‘a’ represents a double value.
Return Value:
The rint () method returns the double value that is close to a.
Special cases are as follows:
- It returns the same result as the argument, if the argument value is equal to mathematical integer.
- The result is same as that of argument, if the argument value is NaN or infinity or positive zero or negative zero.
Example 1:
public class JavaMathRintExample1 { //returns the double value that is close to a public static void main(String[] args) { double a=67.9; System.out.println(Math.rint(a)); } }
Output:
68.0
Example 2:
public class JavaMathRintExample2 { //result is same as that of argument, if the argument value is NaN public static void main(String[] args) { double a=Double.NaN; System.out.println(Math.rint(a)); } }
Output:
NaN
Example 3:
public class JavaMathRintExample3 { //result is same as that of argument, if the argument value is Negative infinity public static void main(String[] args) { double a=Double.NEGATIVE_INFINITY; System.out.println(Math.rint(a)); } }
Output:
-Infinity
Example 4:
public class JavaMathRintExample4 { //result is same as that of argument, if the argument value is zero public static void main(String[] args) { double a=-0d; System.out.println(Math.rint(a)); } }
Output:
-0.0