Java Math round() Method
Example
Round numbers to the nearest integer:
System.out.println(Math.round(0.60));
System.out.println(Math.round(0.40));
System.out.println(Math.round(5));
System.out.println(Math.round(5.1));
System.out.println(Math.round(-5.1));
System.out.println(Math.round(-5.9));
Definition and Usage
The round() method rounds a number to the
nearest integer.
Syntax
One of the following:
public static long round(double number)
public static int round(float number)
Parameter Values
| Parameter | Description |
|---|---|
| number | Required. A number to round. |
Technical Details
| Returns: | A long value (if the argument is double) or int (if the argument is float) value representing the nearest integer to a number. |
|---|---|
| Java version: | Any |
❮ Math Methods