分页总数计算,根据总记录数获取分页总数,本文章提供5种写法,大家感觉哪个好用就拿去用吧。
int pageSize = 20; //每页记录数量
int totalCount = 100005; //总记录数
int pageCount; //总页数
//方法一:
pageCount = (totalCount + pageSize - 1) / pageSize; //推荐写法
//方法二:
pageCount = (totalCount - 1) / pageSize + 1;
//方法三:
pageCount = (int)Math.Ceiling((double)totalCount / pageSize);
//方法四:
pageCount = (int)Math.Ceiling((double)totalCount / pageSize);
//方法五:
pageCount = totalCount%pageSize == 0 ? totalCount/pageSize : totalCount/pageSize + 1;