Java StrictMath - round() Method
The java.lang.StrictMath.round() method returns the value of argument rounded to its nearest integer. In special cases it returns the following:
- If the argument is NaN, the result is 0.
- If the argument is negative infinity or any value less than or equal to the value of Long.MIN_VALUE, the result is equal to the value of Long.MIN_VALUE.
- If the argument is positive infinity or any value greater than or equal to the value of Long.MAX_VALUE, the result is equal to the value of Long.MAX_VALUE.
Syntax
public static long round(double a)
Parameters
a |
Specify a floating point value to be rounded. |
Return Value
Returns the value of argument rounded to its nearest long value.
Exception
NA.
Example:
In the example below, round() method returns the value of argument rounded to its nearest long value.
import java.lang.*; public class MyClass { public static void main(String[] args) { System.out.println(StrictMath.round(48.45)); System.out.println(StrictMath.round(48.55)); } }
The output of the above code will be:
48 49
❮ Java.lang - StrictMath