最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - How to get whole number when dividing 2 numbers in JavaScript - Stack Overflow

programmeradmin6浏览0评论

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
  • you have to make use od Math.ceil () function – EnterJQ Commented Feb 19, 2013 at 7:09
  • @Smartboy Why? floor would give you 6. – JJJ Commented Feb 19, 2013 at 7:10
  • 1 how to downvote a comment? – DDK Commented Feb 19, 2013 at 7:11
  • @Smartboy: The logic here compels the use of ceil function. – nhahtdh Commented Feb 19, 2013 at 7:11
Add a comment  | 

4 Answers 4

Reset to default 8

Try:

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

发布评论

评论列表(0)

  1. 暂无评论