PHP ceil() Function
The PHP ceil() function returns the next highest integer value by rounding up the specified number, if necessary. In other words, it rounds the fraction UP of the given number. In special cases it returns the following:
- If the argument value is already an integer, then the result is the same as the argument.
- If the argument is NAN or infinity, then the result is the same as the argument.
- If the argument value is less than zero but greater than -1.0, then the result is negative zero.
Syntax
ceil(number)
Parameters
number |
Required. Specify a number. |
Return Value
Returns the next highest integer value by rounding UP the specified number, if necessary.
Example:
In the example below, ceil() function is used to round the fraction UP of the specified number.
<?php echo "ceil(10.5) = ".ceil(10.5)."\n"; echo "ceil(-10.5) = ".ceil(-10.5)."\n"; echo "ceil(0.5) = ".ceil(0.5)."\n"; echo "ceil(-0.5) = ".ceil(-0.5)."\n"; echo "ceil(INF) = ".ceil(INF)."\n"; echo "ceil(-INF) = ".ceil(-INF)."\n"; echo "ceil(NAN) = ".ceil(NAN)."\n"; ?>
The output of the above code will be:
ceil(10.5) = 11 ceil(-10.5) = -10 ceil(0.5) = 1 ceil(-0.5) = -0 ceil(INF) = INF ceil(-INF) = -INF ceil(NAN) = NAN
❮ PHP Math Reference