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/*  w w w. ja va2  s . c o  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.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions