Javascript使用舍入到最接近的10 [英] Javascript using round to the nearest 10
本文介绍了Javascript使用舍入到最接近的10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用JavaScript循环整数。例如:
I would like to round integers using JavaScript. For example:
10 = 10
11 = 20
19 = 20
24 = 30
25 = 30
29 = 30
推荐答案
这应该这样做:
Math.ceil(N / 10) * 10;
其中N是您的一个号码。但是,这对你的第一个案例不起作用(10轮到20轮,但为什么会这样?)。
Where N is one of your numbers. However, this does not work for your first case (10 rounds to 20, but why would it?).
这篇关于Javascript使用舍入到最接近的10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文