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

Java Math.round() Method

Java Math.round() Method

The Math.round() method in Java Math is used To the nearest value, round the decimal numbers. This method is used to return to argument the closest long, with ties rounding to positive infinity.

Syntax

public static int round(float x)  
public static long round(double x)  

Parameter

x= This parameter is used to a floating-point value to be rounded to an integer

Return

It is used to returns the value of the argument rounded to the nearest int value.

  1. This method returns the nearest value if the argument is positive or negative number.
  2. This method returns Zero if the statement is not a number (-1).
  3. If the argument is positive Infinity or any value less than or equal to the value of Integer. MIN VALUE, then Integer. MIN VALUE will return this method.

Java Math.round() Method Example 1


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

Output:
14

Java Math.round() Method Example 2


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

Output:
-16