Return the closest integer to a floating-point value.
The Math.round() method returns the closest long (for double arguments) or int (for float arguments) to the argument, with ties rounding towards positive infinity. This means 0.5 rounds to 1, and -0.5 rounds to 0.
This is equivalent to (long) Math.floor(a + 0.5d) for double arguments. The rounding behavior differs from "round half to even" (banker's rounding) used by some other systems.
Special cases: if the argument is NaN, the result is 0. If the argument is negative infinity or less than Long.MIN_VALUE, the result is Long.MIN_VALUE. If the argument is positive infinity or greater than Long.MAX_VALUE, the result is Long.MAX_VALUE.
| Name | Description | Optional |
|---|---|---|
a |
The floating-point value to be rounded. | No |
Math.round(4.5); // 5
Math.round(4.4); // 4
Math.round(-4.5); // -4
Math.round(4.0); // 4