简体   繁体   中英

count of pages for a pager

I have X number of items and I want to count how many pages I'll need to page these items if I can put 5 items per page.

This is what I have:

int TotalPages = (int)(Math.Ceiling(TheItemCount / 5));

The line is underlined in red with an error that's saying there's an

ambigious call between Math.Ceiling (double) and Math.Ceiling (decimal)

I know this is supposed to be simple but I'm not getting the result I want. What do I need to change in my code to make it work?

Thanks.

The issue is that the compiler can't figure out which overload you want, so just force it to use the one of them:

int TotalPages = (int)(Math.Ceiling((double)TheItemCount / 5.0));

another way would be this:

int TotalPages = (int)(Math.Ceiling(Convert.ToDouble(TheItemCount / 5)));

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM