There are several occurrences when we want to get the ceil value of an integer to round it off and then use that value later on.
The Ceiling value of a number is the value that is rounded to the closest integer greater than or equal to that integer.
Lua provides us with a math.ceil() function that we can use to find the ceil value of a number.
Let’s consider a simple example where we will make use of the math.ceil() function in Lua −
a = math.ceil(3.3) b = math.ceil(7.1) print(a) print(b)
It should be noted that if we try to find ceil of a number which is already the closest integer to itself, then we will get the same number as the output. Consider the example shown below −
c = math.ceil(8) print(c)
We can also pass negative numbers in the math.ceil() function as an argument.
Consider the example shown below −
d = math.ceil(-3.3) print(d)