I’m creating some pagination and I’m getting an issue.
If I have a number 12 and I want to divide that by 5 (5 is the number of results I want on a page), how would I round it up properly? This doesn’t work:
int total = 12;
int pages = Math.Ceiling(12 / 5);
//pages = 2.4... but I need it to be 3
Even though your code should work,
Math.Roundis wrong though, you could try this:That should be the same as
Math.Ceilingexcept that you are always dealing withintand notdoubleat any point asMath.Ceilingreturns.EDIT: To get your code to work you could try:
But you should use the first example.