int and float in lua

In Lua, there is no specific data type for integers (int) or floating-point numbers (float). Instead, Lua uses a single numeric data type called "number" to represent both integers and floating-point numbers. The "number" type can hold both integer and floating-point values.

When you assign a whole number to a variable in Lua, it is automatically treated as an integer. For example:

local num = 10
print(num) -- Output: 10

In this example, the variable num is assigned the value 10, which is treated as an integer.

Similarly, when you assign a number with a fractional part to a variable, it is automatically treated as a floating-point number. For example:

local num = 3.14
print(num) -- Output: 3.14

In this example, the variable num is assigned the value 3.14, which is treated as a floating-point number.

Lua provides some built-in functions that allow you to convert a number to an integer or a floating-point number explicitly if needed. These functions are math.floor() and math.ceil().

The math.floor() function rounds a number down to the nearest integer. For example:

local num = 3.7
print(math.floor(num)) -- Output: 3

In this example, the math.floor() function is used to round down the value of num to the nearest integer, which is 3.

On the other hand, the math.ceil() function rounds a number up to the nearest integer. For example:

local num = 3.2
print(math.ceil(num)) -- Output: 4

In this example, the math.ceil() function is used to round up the value of num to the nearest integer, which is 4.

These functions can be useful when you need to explicitly convert a number to either an integer or a floating-point number in Lua.