Round to hundreds with javascript

I want to round numbers to hundreds using javascript:

10651.89 = 10700 10649.89 = 10600 60355.03 = 60400 951479.29 = 951500 1331360.95 = 1331400 

How can i do this?

Many thanks.

+4
source share
4 answers
 function roundHundred(value){ return Math.round(value/100)*100 } 

Live example with your test cases: http://jsfiddle.net/LaPGs/

+11
source

you can divide it by 100 first, then use Math.round and finally multiply it by 100.

 > Math.round(10651.89 / 100) * 100 10700 
+4
source
 function(x) { return Math.round(x / 100) * 100; } 
+1
source

we can use Math.ceil for this.

 var rawNumber = 10651.89; roundFigure= Math.ceil(rawNumber /100)*100 
0
source

Source: https://habr.com/ru/post/1393709/


All Articles