The round() method rounds the specified value to the closest int or long value and returns it. That is, 3.87 is rounded to 4 and 3.24 is rounded to 3.
Example
Syntax of Math.round()
The syntax of the round() method is:
Math.round(value)
Here, round() is a static method. Hence, we are accessing the method using the class name, Math.
round() Parameters
The round() method takes a single parameter.
- value - number which is to be rounded
Note: The data type of the value should be either float or double.
round() Return Value
- returns the
intvalue if the argument isfloat - returns the
longvalue if the argument isdouble
The round() method:
- rounds upward if the value after the decimal is greater than or equal to 5
1.5 => 2 1.7 => 2 - rounds downward if the value after the decimal is smaller than 5
1.3 => 1