Syntax
local rounded = math.round(value)Examples
Luau nearest-integer rounding
Run as a standalone current Luau script, or as a Script in Roblox Studio ServerScriptService. No Roblox engine APIs are required; type-annotated syntax is not standard Lua.
print(math.round(2.5))
print(math.round(-2.5))
local step = 0.25
local snapped = math.round(1.13 / step) * step
print(snapped)- Output: 3, -3, 1.25. Scaling by a step before rounding snaps a value to a grid.
Best practices
- Choose the rounding rule explicitly. Floating-point grid snapping does not provide exact decimal accounting.
Runtime & versions
Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Luau documentation