在 JavaScript 中除以 2 个数字时如何获得整数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14951680/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 23:00:11  来源:igfitidea点击:

How to get whole number when dividing 2 numbers in JavaScript

javascriptjquery

提问by Smartboy

I am implementing paging in JavaScript,

我正在用 JavaScript 实现分页,

Now if I have total_item_count = 69and I want 10 records per page then it should show 7 pages but it is showing 6 pages.

现在,如果我有total_item_count = 69并且我想要每页 10 条记录,那么它应该显示 7 页,但它显示的是 6 页。

What I am doing:

我在做什么:

var totalpages = 69/10 ; // it should give 7 but its giving 6 

Thanks in advance.

提前致谢。

回答by TimPetricola

If you want to get the upper integer you can use ceil:

如果你想获得上整数,你可以使用ceil

var totalpages = Math.ceil(69/10);

回答by Anujith

Try:

尝试:

var Totalpages = Math.ceil(Total Records/ Records per Page);

Here:

这里:

var Totalpages = Math.ceil(69/10);   // gives 7

回答by bipen

try this

试试这个

var totalpages = Math.ceil(69/10) ;

ceil(): Round a number upward to it's nearest integer:

ceil():将一个数字向上舍入到最接近的整数:

回答by DDK

use Math.ceilto get the upper integer.

用于Math.ceil获取上整数。

Math.ceil(69/10)should give you 7

Math.ceil(69/10)应该给你 7