Lua 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.

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
    • Beginner Friendly.
      4 hours

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

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn the basics of Lua, a general-purpose programming language used for building games, web apps, and developer tools.
    • Beginner Friendly.
      4 hours