PHP Tutorial - PHP ceil() Function






Definition

The ceil() function rounds a floating-point number to the nearest integer above its current value. If you provide an integer, nothing will happen.

The ceil() function rounds a number UP to the nearest integer, if necessary.

Syntax

PHP ceil() Function has the following format.

float ceil ( float num )

Parameter

Parameter Is Required Description
numberRequired.Value to round up

Return

Item Description
Return ValueThe value rounded up to the nearest integer
Return Type Float




Note

To round a number DOWN to the nearest integer, look at the floor() function. To round a floating-point number, look at the round() function.

Example

Round numbers up to the nearest integer:


<?php/*from w ww. j  ava  2s  .  co  m*/

$number = ceil(11.9); // 12 
print($number);
print "\n";
$number = ceil(11.1); // 12 
print($number);
print "\n";
$number = ceil(11); // 11 
print($number);
print "\n";

echo(ceil(0.60) . "\n");
echo(ceil(0.40) . "\n");
echo(ceil(5) . "\n");
echo(ceil(5.1) . "\n");
echo(ceil(-5.1) . "\n");
echo(ceil(-5.9));
?>

The code above generates the following result.