![]() |
VOOZH | about |
math.ceil() function returns the smallest integer greater than or equal to a given number. It always rounds a value upward to the nearest whole number. If the input is already an integer, the same value is returned.
This example shows how math.ceil() rounds a positive decimal number up to the next integer.
34
math.ceil(x)
Example 1: This example demonstrates how the function behaves with negative values. It still returns the smallest integer that is not less than the given number.
-13
Explanation: math.ceil(-13.1) returns -13 because it is the smallest integer greater than or equal to -13.1.
Example 2: This example applies math.ceil() to a list of decimal numbers and prints their ceiling values one by one.
[3, 8, 102]
Explanation: math.ceil(n) rounds each value in nums upward 2.3 -> 3, 7.01 -> 8, 101.96 -> 102.