I am implementing paging in JavaScript,
Now if I have total_item_count = 69
and I want 10 records per page then it should show 7 pages but it is showing 6 pages.
What I am doing:
var totalpages = 69/10 ; // it should give 7 but its giving 6
Thanks in advance.
I am implementing paging in JavaScript,
Now if I have total_item_count = 69
and I want 10 records per page then it should show 7 pages but it is showing 6 pages.
What I am doing:
var totalpages = 69/10 ; // it should give 7 but its giving 6
Thanks in advance.
Share Improve this question edited Feb 19, 2013 at 7:13 mjgpy3 8,9375 gold badges33 silver badges53 bronze badges asked Feb 19, 2013 at 7:05 SmartboySmartboy 1,0066 gold badges24 silver badges37 bronze badges 4 |4 Answers
Reset to default 8Try:
var Totalpages = Math.ceil(Total Records/ Records per Page);
Here:
var Totalpages = Math.ceil(69/10); // gives 7
If you want to get the upper integer you can use ceil
:
var totalpages = Math.ceil(69/10);
try this
var totalpages = Math.ceil(69/10) ;
ceil(): Round a number upward to it's nearest integer:
use Math.ceil
to get the upper integer.
Math.ceil(69/10)
should give you 7
ceil
function. – nhahtdh Commented Feb 19, 2013 at 7:11