Quirrel4.41.0

math.floor

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

Rounds x downward to the nearest integer

Parameters

xnumberthe number to round

Return value

The largest integer value that is not greater than x.

Notes

The result is always a float, even when x is already an integer: type(floor(3)) gives "float", not "integer". Convert with int(...) when an integer value is required.

Example

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

println("floor(3.7) =", floor(3.7))
println("floor(-3.7) =", floor(-3.7))

// the result is a float even though it already looks like a whole number
println("type(floor(3.7)) =", type(floor(3.7)))
println("type(floor(3)) =", type(floor(3)))
Output:
floor(3.7) = 3
floor(-3.7) = -4
type(floor(3.7)) = float
type(floor(3)) = float

See also

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