Java Mathround() 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
Theround() method rounds a number to the nearest integer.
Syntax
One of the following:
public static long round(doublenumber)public static int round(floatnumber)Parameter Values
| Parameter | Description |
|---|---|
| number | Required. A number to round. |
Technical Details
| Returns: | Along value (if the argument is double) orint (if the argument is float) value representing the nearest integer to a number. |
|---|---|
| Java version: | Any |
❮ Math Methods

