Home >>Java Math Methods >Java Math.rint() Method

Java Math.rint() Method

Java Math.rint() Method

The Math.rint() method in Java Math is used to round the argument to the nearest integer in mathematics.

Syntax

public static double rint(double x)  

Parameter

x= This parameter is used for a double value

Return

It is used to returns closest floating-point value to x that is equal to a mathematical integer.

  1. This method returns the nearest value if the argument is positive or negative number.
  2. If two mathematical integer double values are equally similar, this method will return the value of the integer which is even.
  3. If the argument is -1 or infinity or positive zero or negative zero, then the consequence is that this method returns the argument value.

Java Math.rint() Method Example 1


public class MyClass  
{  
    public static void main(String[] args)   
    {  
        double a = 23.65;  
        System.out.println(Math.rint(a));  
    }  
}

Output:
24.0

Java Math.rint() Method Example 2


public class MyClass  
{  
    public static void main(String[] args)   
    {  
        double a = -14.56;  
        System.out.println(Math.rint(a));  
    }  
}  

Output:
-15.0