|
ceil(x) |
|
x = Any number.
This function rounds up (as in 'up to the ceiling') the number to the nearest whole number, so wholenumber in Example #1 would return 11. This function is particularly useful when checking for random numbers, because random(x) can return a real number (5.65, 10.3,etc), you can use ceil to round the number to a whole number.
Example #1:
Please note that the code ceil(random(3)) can in rare cases return 0. This has been discussed so many times in the Q and A forum. Returning a 0 happens very, very rarely but it is a real possibility, therefore the code must include that possibility:
Example #2:
(See the switch statement for further details on switch).
Thanks to Weird Dragon for corrections - Revision #3 |