PHP ceil function – Round fractions up

Description

Returns an integer that is the next larger than the float used as the argument. In essence, it rounds up a floating-point number to an integer, no matter what the value of the floating-point integer is. It doesn’t round down.

Syntax:

ceil(int|float $num): float

The ceil() function takes a floating-point number as its only parameter and rounds it to the nearest integer above its current value. If you provide an integer, nothing will happen. For example:

$number = ceil(11.9); // 12
$number = ceil(11.1); // 12
$number = ceil(11); // 11

Parameters

Parameter Description
num The value to round.

Return Values

num rounded up to the next highest integer. The return value of ceil() is still of type float as the value range of float is usually bigger than that of int.

Examples

Example 1: Round up a floating-point number:

$number = 12.023; 
echo "The next highest integer of $number is ", ceil($number);

Example 2:

echo ceil(4.3);    // 5
echo ceil(9.999);  // 10
echo ceil(-3.14);  // -3
Related Post