0

I want to know number of items in a page and offset.

For example, I have 20 items in an array and per page 9 items.

Page 1, the number of items is 9 and offset is 0-8.

Page 2, the number of items is 9 and offset is 9-17.

Page 3, the number of items is 2 and offset is 18-19.

I guess I can do this

if pageNo * 9 < 20, means number of items is 9. else if pageNo * 9 > 20 like 27 > 20, number of items is 20 - 9 x (pageNo-1). But I would like to know if there's a shorter version.

Thanks

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 04 '22 at 06:48
  • Think about integer division and the modulus operator. – John Douma Jan 04 '22 at 07:55

0 Answers0