Logic for getting number of pages
Question
If a page can have 27 items printed on it and number of items can be any positive number then how can I find number of pages if I have number of items, I tried Modulus and division but didn't helped.
double TotalNumberOfPages = NumberOfItems/27;
int a = (int)TotalNumberOfPages;
above code works but not logically as if double is 3.00000000000001 I want it to round up as 4 not 3, for some reason I can't use "round" method.
Solution
Surely your TotalNumberOfPages
should be an integer. In that case, try:
int PageSize = 27;
int TotalNumberOfPages = (int)Math.Ceiling((double)NumberOfItems / (double)PageSize);
OTHER TIPS
(NumberOfItems + ItemsPerPage - 1) / ItemsPerPage;
In your case ItemsPerPage = 27
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow