admin管理员组文章数量:1178553
I want to round numbers to hundreds with javascript like this:
10651.89 = 10700
10649.89 = 10600
60355.03 = 60400
951479.29 = 951500
1331360.95 = 1331400
How can I do that ?
Thanks a lot.
I want to round numbers to hundreds with javascript like this:
10651.89 = 10700
10649.89 = 10600
60355.03 = 60400
951479.29 = 951500
1331360.95 = 1331400
How can I do that ?
Thanks a lot.
Share Improve this question edited Jan 30, 2012 at 9:03 Jamiec 136k15 gold badges141 silver badges199 bronze badges asked Jan 30, 2012 at 9:01 DaliDali 7,88228 gold badges114 silver badges178 bronze badges 1- possible duplicate of Round money to nearest 10 dollars in Javascript, take out the money factor and the fact that question is for tens instead of hundreds and the question is the same. Even the answers are identical. – Andy E Commented Jan 30, 2012 at 9:06
4 Answers
Reset to default 25function roundHundred(value){
return Math.round(value/100)*100
}
Live example with your test cases: http://jsfiddle.net/LaPGs/
you can divide it by 100 first then use Math.round
, and finally multiply it by 100.
> Math.round(10651.89 / 100) * 100
10700
we can use Math.ceil for doing this.
var rawNumber = 10651.89;
roundFigure= Math.ceil(rawNumber /100)*100
function(x) {
return Math.round(x / 100) * 100;
}
本文标签: Round to hundreds with javascriptStack Overflow
版权声明:本文标题:Round to hundreds with javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738094558a2062657.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论