What is PHP's function for rounding off excess?
Example:
1.1
pass 2
What is PHP's function for rounding off excess?
Example:
1.1
pass 2
<?php
echo ceil(1.1); // 2
echo ceil(4.3); // 5
echo ceil(9.999); // 10
echo ceil(-3.14); // -3
?>
Use the ceil
function.
ceil(1.1); // Imprime 2
This function is usually used to know the number of pages that will be generated in pagination.
Example:
$total = 100;
$limit = 12;
$pages = ceil($total / $limit); // Imprime 9
It serves to round fractions upwards.
Just to have you add information: The counter function is floor
. It rounds down.
In PHP for overcharging, use the ceil
function.
Example
echo ceil(4.3); // 5