How to round up the result of integer division?

485    Asked by ChrisDyer in Java , Asked on Jun 10, 2021

I'm thinking in particular of how to display pagination controls, when using a language such as C# or Java.

If I have x items that I want to display in chunks of y per page, how many pages will be needed? Want to know more c# divide round up?

Answered by Dipika Agarwal

Here's an elegant solution for c# divide round up:

  int pageCount = (records + recordsPerPage - 1) / recordsPerPage;


Your Answer

Interviews

Parent Categories