The math.ceil() function in lua always rounds up and returns the smallest integer greater than or equal to a given number.


Syntax

math.ceil(x)

Parameters

  • x
    A number.

Return value

The smallest integer greater than or equal to x. It's equivalent to -math.floor(-x).


Description

Because math.ceil() is a static function, it is always used as math.ceil(), rather than as a method of a lua object. This function can be useful for rounding up numbers in various calculations.


Examples

Using math.ceil()

print(math.ceil(-Infinity)) -- -Infinity
print(math.ceil(-7.004))    -- -7
print(math.ceil(-4))        -- -4
print(math.ceil(-0.95))     -- -0
print(math.ceil(-0))        -- -0
print(math.ceil(0))         -- 0
print(math.ceil(0.95))      -- 1
print(math.ceil(4))         -- 4
print(math.ceil(7.004))     -- 8
print(math.ceil(Infinity))   -- Infinity

See also

  • math.abs()
  • math.floor()
  • math.round()
  • math.sign()
  • math.trunc()

Was this page helpful?

Table of Contents