I have 47 entries of text in an SQL database, in Perl, I want to print out the last 15 of these (this is simple, I manage to do this), but I also want to print out how many pages these 47 entries would "occupy", if each page displays 15 entries.
I could do something like this:
This renders unusable due to inaccuracy concerning floats to integers.
(And if the number og entries is smaller than 15, I will get a 0 from int(),
this can easely be fixed like this:
But a number like 47 will return 3.13 when divided by 15, so I will have to increment it to 4 instead of 3.
How should I solve this problem? Thanks in advance!
I could do something like this:
Code:
$entries = 47;
$pages = int($entries / 15);
$page = $entries / 15;
This renders unusable due to inaccuracy concerning floats to integers.
(And if the number og entries is smaller than 15, I will get a 0 from int(),
this can easely be fixed like this:
Code:
if ($pages == 0) {$pages = 1;}
But a number like 47 will return 3.13 when divided by 15, so I will have to increment it to 4 instead of 3.
How should I solve this problem? Thanks in advance!