ceil
Rounds a number up to an integer.
Syntax
ceil(int|float $num): floatParameters
| Parameter | Type | Description |
|---|---|---|
| $num | int|float | The number to round. |
Return value
floatThe nearest integer not less than the number.
Examples
Rounding up:
<?php
echo ceil(4.2), "\n";
echo ceil(-4.8);Output:
5
-4The number of pages for 45 records at 10 per page:
<?php
echo ceil(45 / 10);Output:
5Notes
The result has the type float although it looks like an integer. For a strict comparison cast it: (int) ceil($value).
See also
Related recipes
In the tutorial
- Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.