PHP ceil() Function

In this chapter you will learn:

  1. Definition for PHP ceil() Function
  2. Syntax for PHP ceil() Function
  3. Parameter for PHP ceil() Function
  4. Return for PHP ceil() Function
  5. Note for PHP ceil() Function
  6. Example - Round numbers up to the nearest integer

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  java2  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.

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP cos() Function
  2. Syntax for PHP cos() Function
  3. Parameter for PHP cos() Function
  4. Return for PHP cos() Function
  5. Example - Return the cosine of different numbers