ceil(): Getting the higher integer value

echo ceil(2.7).'<br>'; // Output 3
echo ceil(2.4).'<br>'; // Output 3
echo ceil(2.5).'<br>'; // Output 3
echo ceil(-10.8).'<br>'; // Output -10
echo ceil(-10.3).'<br>'; // Output -10
echo ceil(-10.5).'<br>'; // Output -10
echo ceil(49/10).'<br>'; // Output  5
float ceil ( float $input )
$input : Required : Input value in Integer or float

From a number we can find out the next higher integer using ceil function.

round() and ceil()

In case of round() function the value is rounded to higher or lower value, but here it is always higher value is returned.


This function is useful when we search for a next higher hundred or thousand value of a number. For example we have a number 785 and wants to know what is the next higher hundredth number ( that is 800 ). To know this we can use ceil function. If you are generating a graph and coordinates are fixed according to high and low value of the data then using this function we can find out what should be our highest point in the graph.
//$v_max equal to 500
Same way we can find out the nearest lower value of a number using floor function in php
//$v_min equal to 400
Here is a comparison between ceil(), floor() and round() function. For different input numbers we will get different values by using these functions.
Note that there is no point is using ceil or floor functions on integers directly. ( we will get the same value )

Example of uses of ceil function

Find out number of pages required to display 10 records per page.
While displaying fixed number of records per page and giving links to navigate to different pages ( known as pagination ) we can find out the number of pages by using ceil function. The number of pages will always have the closest integer value divisible by records per page which is higher than the number of records.

We are displaying 10 records per page.
If we have 41 records then we will have 5 pages and last page will show 1 record.
If we have 49 records then we will have 5 pages and last page will show 9 records.
If we have 50 records then we will have 5 pages and last page will show 10 records.
echo ceil(49/10).'<br>'; // Output  5

Math Functions pow() to get exponential value
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net


    Post your comments , suggestion , error , requirements etc here

    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer