Getting the higher integer using ceil function in PHP
$input : Required : Input value in float
IN an umber we can find out the next higher integer using ceil function. This function is different than round() function. In case of round function the value is rounded to higher or lower value, but here it is always higher value is returned. Here is an example
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.
Same way we can find out the nearest lower value of a number using floor function in php
Here is a comparison between ceil(), floor() and round() function. For different input numbers we will get different values by using these functions.
Example of uses of ceil functionFind 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.
This article is written by plus2net.com team.