Reference · Math

floor

signature
floor(num | dec) -> num | dec

What it does

The largest whole number not above the argument: 2.7 gives 2, -2.7 gives -3. An int or a float gives an int; a decimal gives a decimal with no decimals.

Examples

print(floor(2.7), floor(-2.7), floor(3), floor(2.0))print(floor(2.7m), floor(-2.7m))print(floor(7 / 2))
output
2 -3 3 22 -33

Edge cases

print(floor(-0.5), int(-0.5))print(type_of(floor(2.7)), type_of(floor(2.7m)), floor(2.50m))print(floor(1e16), type_of(floor(1e16)), floor(float("inf")))let a = 9007199254740995print(floor(a / 2), a / 2 | floor, floor(-7 / 2))let q = a / 2print(floor(q), type_of(q))
output
-1 0int dec 210000000000000000 int inf4503599627370497 4503599627370497 -44503599627370498 float

Errors

A string, null or a boolean is a runtime error, not an error value.

this one fails
print(floor("x"))
output
line 1: `floor` expects a number as argument 1, got str

Chaining

print(3.7 | floor, [1.9, 2.1] | map(floor))print(17 / 5 | floor, 17 % 5)
output
3 [1, 2]3 2

See also

ceil, round, int, abs

Thread
5Useful? Like it, or add to its thread below.

Thread 0 posts

On floor(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo