w do you round a double the nearest whole numbe
How do you round a double the nearest whole number in Java?
Description
The java.lang.Math.round(double a) returns the closest long to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type long. Special cases −
-
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.
-
If the argument is NaN, the result is 0.
-
Declaration IS ARE AS FOLLOWS:
Following is the declaration for java.lang.Math.round() method
public static long round(double a)
Parameters
a − a floating-point value to be rounded to a long.
Return Value
This method returns the value of the argument rounded to the nearest long value.
Exception
NA
Trending now
This is a popular solution!
Step by step
Solved in 2 steps