Skip to main content

round

Function round 

Source
pub fn round(x: number, ndigits: option<number>) -> number
Available on crate feature extended only.
Expand description

Rounds a number to the nearest integer, halves away from zero. Extended library — feature extended (from extended.lua).

§Parameters

  • ndigits: round to this many decimal places instead; the result is then a float.

§Examples

print(math.round(2.5))          --> 3
print(math.round(-2.5))         --> -3
print(math.round(2.4))          --> 2
print(math.round(3.14159, 2))   --> 3.14

§See also

floor, ceil