math.round
Rounds to the nearest integer, halves away from zero.
Syntax
math.round(x: number) -> number
Parameters
| Parameter | Type | Description |
|---|---|---|
x | number | Value to round. |
Returns
| Type | Description |
|---|---|
number | Nearest integer as a float. |
Description
Uses the Luau rule, so 0.5 rounds to 1 and -0.5 to -1 rather than toward zero.
The result is a number, not an integer subtype.
Example
print(math.round(2.4)) -- 2
print(math.round(2.5)) -- 3
print(math.round(-2.5)) -- -3
Notes
math.floor(x + 0.5)— Differs for negative halves; prefermath.round.