我想用这样的javascript将数字舍入到数百:
10651.89 = 10700
10649.89 = 10600
60355.03 = 60400
951479.29 = 951500
1331360.95 = 1331400
我该怎么做?
非常感谢。
答案 0 :(得分:13)
function roundHundred(value){
return Math.round(value/100)*100
}
测试用例的实例:http://jsfiddle.net/LaPGs/
答案 1 :(得分:4)
你可以先将其除以100,然后使用Math.round
,最后将其乘以100。
> Math.round(10651.89 / 100) * 100
10700
答案 2 :(得分:1)
function(x) {
return Math.round(x / 100) * 100;
}
答案 3 :(得分:0)
我们可以使用Math.ceil来执行此操作。
var rawNumber = 10651.89;
roundFigure= Math.ceil(rawNumber /100)*100