I have three integer type variable
Suppose at initial level i have this
Totallistcount = 14;
perpagecount = 9;
Now I have a formula to found total number of pages possible
totalpagescount = Totallistcount / perpagecount ;
but in this situtation I got 1
in totalpagescount
but I need 2
in totalpagescount
, because 9 items on the first page and rest of item will be displayed on last page , How can I do this
Thanks ,
totalpagescount = (Totallistcount + perpagecount - 1) / perpagecount ;
If you want to round up, you need to perform the division as a floating point number, then call Math.Ceiling
to get the next-highest whole number.
double quotient = Totallistcount / (double)perpagecount;
double ceiling = Math.Ceiling(quotient);
int totalpagescount = (int)ceiling;
an other solution :
int pageCount = (records - 1) / recordsPerPage + 1;
int pageCount = (14 - 1) / 9 + 1; => pagecount = 2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.