CEIL
ceil( a )
ceil | "ceiling" |
a | a number |
The ceil( a ) function is used to round up the given number, a
, and return the nearest larger whole number.
For example, if we call ceil(4.02)
, the function will round up to the nearest whole number and return that value. Therefore, it will return 5
.
value = flr(4.02)
print(value) --prints 5
If we pass a negative number, for example flr(-8.6)
, the function will return -8
since it is the nearest larger whole number.
value = flr(-8.6)
print(value) --prints -8
There are many reasons you may want to use ceil()
. For example, in games that involve damage, health, or currency, you might want to ensure that these values are always rounded up to the nearest whole number. For example, if a character takes 3.2
points of damage, you might use ceil()
to round that up to 4
points of damage because of a small powerup.
Images in this Guide by NerdyTeachers is licensed under CC BY-SA 4.0
600
22 Nov 2023