What is ceil() in PHP?

The ceil() function returns the smallest integer that is greater than or equal to the number whose ceiling needs to be calculated.

The following illustration shows the mathematical representation of the ceil() function and the corresponding expression in PHP.

Mathematical representation of ceil() function and the corresponding expression in PHP

Syntax

ceil(int|float $num): float

Parameter

This function requires a number to round up as a parameter.

Return value

ceil() returns the nearest smallest integer greater than or equal to the number sent as a parameter.

The function’s return type is float as the value range of float is greater than that of the integer.

Example

<?php
#Positive number
echo ("ceil(10): ");
echo (ceil(10));
echo ("\n");
echo ("ceil(5.3): ");
echo (ceil(5.3));
?>
<?php
#Negative number
echo ("ceil(-10): ");
echo (ceil(-10));
echo ("\n");
echo ("ceil(-5.3): ");
echo (ceil(-5.3));
?>

Free Resources