ceil()

abereFejiro9953409650's avatar
Published Oct 15, 2023
Contribute to Docs

The ceil() function in Lua’s math library rounds up a given number to the smallest integer that is greater than or equal to the passed value. The given number can be a positive or negative number.

Syntax

math.ceil(x)
  • x: The number to be rounded up.

Example

In this example, math.ceil() is used to round a pair of values.

local num1 = 14.4
local num2 = -22.5
local ceilNum1 = math.ceil(num1)
local ceilNum2 = math.ceil(num2)
print(ceilNum1)
print(ceilNum2)

This will result in the following output:

15
-23

All contributors

Contribute to Docs

Learn Lua on Codecademy