sof-03
sof-03

Reputation: 2505

How to get the right page count?

I am new to JavaScript, I want to get the right page count.

if one page the item count is 20, and the page count is 23, the page should be 2.

var count = 23

var per_page_count = 20

If in other language we can use:

count / per_page_count + 1

to get the page count, but in JavaScript we can not get it.

I also tried use Math.round, still not work

console.log(Math.round(count/per_page_count))  // there I want to get 2, but get 1

Upvotes: 1

Views: 1451

Answers (2)

Sisay Kassahun
Sisay Kassahun

Reputation: 1

I think you are trying to implement some sort of pagination. So I would suggest :

Maths.ceil(count/per_page_count)

Upvotes: -1

aircraft
aircraft

Reputation: 26924

You can use

Math.ceil(count/per_page_count)

The Math.ceil() function returns the smallest integer greater than or equal to a given number.

from Math.ceil document.

Upvotes: 7

Related Questions