Reputation: 7882
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.
Upvotes: 12
Views: 13080
Reputation: 966
we can use Math.ceil for doing this.
var rawNumber = 10651.89;
roundFigure= Math.ceil(rawNumber /100)*100
Upvotes: 4
Reputation: 136114
function roundHundred(value){
return Math.round(value/100)*100
}
Live example with your test cases: http://jsfiddle.net/LaPGs/
Upvotes: 25
Reputation: 18219
you can divide it by 100 first then use Math.round
, and finally multiply it by 100.
> Math.round(10651.89 / 100) * 100
10700
Upvotes: 5