The math.floor() function returns the largest integer less than or equal to a given number.
Syntax
math.floor(`x`)
Parameters
x
A number.
Return value
The largest integer smaller than or equal to x.
Description
Because math.floor() is a static function, it is always used as math.floor(), rather than as a method of a Math object you created (Math is not a constructor).
Examples
Using math.floor()
print(math.floor(-math.huge)) -- -Infinity
print(math.floor(-45.95)) -- -46
print(math.floor(-45.05)) -- -46
print(math.floor(0)) -- 0
print(math.floor(4)) -- 4
print(math.floor(45.05)) -- 45
print(math.floor(45.95)) -- 45
print(math.floor(math.huge)) -- Infinity
Specifications
- Specification: lua 5.1 (and later)
See also
-
math.abs(x)
Returns the absolute value ofx. -
math.ceil(x)
Returns the smallest integer greater than or equal tox. -
math.round(x)
Roundsxto the nearest integer (not natively available in lua). -
math.trunc(x)
Returns the integer portion ofx(not natively available in lua).