📜  lua math floor - Lua (1)

📅  最后修改于: 2023-12-03 15:02:48.553000             🧑  作者: Mango

Lua math.floor()

The math.floor() function in Lua returns the largest integer that is less than or equal to the given number. It rounds the number down to its nearest integer.

Syntax

The syntax for the math.floor() function is as follows:

math.floor(x)

where x is the number to be rounded down to its nearest integer.

Example
print(math.floor(3.14)) --> 3
print(math.floor(-3.14)) --> -4

In the first example above, math.floor(3.14) returns 3 because 3 is the largest integer that is less than or equal to 3.14.

In the second example, math.floor(-3.14) returns -4 because -4 is the largest integer that is less than or equal to -3.14.

It is important to note that math.floor() works on all types of numerical values and not just floating-point numbers.

Conclusion

The math.floor() function in Lua is a useful tool for rounding down any numerical value to its nearest integer. It is simple to use and can be combined with other Lua functions for powerful mathematical operations.