
Wikis & learning
Round a page estimate upward
A list with a partial final page still needs a page for those remaining entries. Calculate the quotient first, then choose a rounding rule based on what the result represents.
A list with a partial final page still needs a page for those remaining entries. Calculate the quotient first, then choose a rounding rule based on what the result represents.
Walkthrough
ceil moves a fractional value to the next whole number. intdiv gives a whole-number quotient instead. Printing both answers beside the remainder makes it easier to understand when the last page is needed.
PHP example
<?php
$entries = 21;
$pageSize = 10;
echo intdiv($entries, $pageSize), ' full pages; ';
echo ceil($entries / $pageSize), ' pages total; ';
echo $entries % $pageSize, ' remaining';Expected output
2 full pages; 3 pages total; 1 remainingChange and check
Set the entry count to 20 and then to 0. Both functions should agree whenever no partial page remains. A real page size must be positive.
Discussion
Sign in to participate.



