Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

ceil

Rounds a number up to an integer.

Syntax

ceil(int|float $num): float

Parameters

ParameterTypeDescription
$numint|floatThe 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
-4

The number of pages for 45 records at 10 per page:

<?php
 
echo ceil(45 / 10);

Output:

5

Notes

The result has the type float although it looks like an integer. For a strict comparison cast it: (int) ceil($value).

See also

  • floor — Rounds a number down to the nearest integer.
  • round — Rounds a number to a given number of digits.

Related recipes

In the tutorial

  • Numbers and maths — PHP's maths functions — rounding, number formatting, random numbers and the precision of fractions.

Thanks for reading!

Donate to the site — we work hard for you.