Quirrel4.41.0

math.round

Defined in module "math"
from "math" import round
pure fastcall round(x: number): float

Rounds x to the nearest integer

Parameters

xnumberthe number to round

Return value

The nearest integer value to x, as a float.

Notes

A halfway value rounds away from zero, not to the nearest even integer: round(2.5) is 3 and round(-2.5) is -3.

Example

examples/math/round.nut
from "math" import round

println("round(2.4) =", round(2.4))
println("round(2.6) =", round(2.6))

// a halfway value rounds away from zero, not to the nearest even integer
println("round(2.5) =", round(2.5))
println("round(-2.5) =", round(-2.5))
println("type(round(2.5)) =", type(round(2.5)))
Output:
round(2.4) = 2
round(2.6) = 3
round(2.5) = 3
round(-2.5) = -3
type(round(2.5)) = float

See also

floorRounds x downward to the nearest integer
ceilRounds x upward to the nearest integer
absReturns the absolute value of x
mathmodule index