The simplest formula to calculate page count?

NOTE: you will always get at least 1 page, even for 0 count, if the page size is > 1, which is what I needed but may not be what you need. A page size of 1(silly but technically valid) and a count of 0 would be zero pages. Depending on your needs you may want to check for a zero value for count & page size of 1

int pages = ((count - 1) / PAGESIZE) + 1;

Force it to round up:

totalPage = (imagesFound.Length + PageSize - 1) / PageSize;

Or use floating point math:

totalPage = (int) Math.Ceiling((double) imagesFound.Length / PageSize);

Tags:

C#

Pagination