math.ceil

Shared

Rounds a number up to the nearest integer


Syntax

local result = math.ceil(
    value
)

Parameters

TypeNameDescription
numbervalueNumber to round up

Returns

TypeNameDescription
intresultSmallest integer greater than or equal to value

Examples

Ceil a positive float
local result = math.ceil(4.2)

engine.print("info", result) -- 5
Ceil a negative float
local result = math.ceil(-4.2)

engine.print("info", result) -- -4
Ceil an exact integer returns itself
local result = math.ceil(7.0)

engine.print("info", result) -- 7
Ceil a value just below an integer
local result = math.ceil(2.0001)

engine.print("info", result) -- 3
Calculate number of pages needed for items
local itemCount = 17
local perPage = 5
local pages = math.ceil(itemCount / perPage)

engine.print("info", pages) -- 4
Round up to the next whole unit
local bytes = 1500
local kb = math.ceil(bytes / 1024)

engine.print("info", kb) -- 2
Ensure minimum allocation size
local required = 3.1
local allocated = math.ceil(required)

engine.print("info", allocated) -- 4

On this page