Abs Abs - 1 month ago 8x
Javascript Question

How to round an integer up or down to the nearest 10 using Javascript

Using Javascript, I would like to round a number passed by a user to the nearest 10. For example, if 7 is passed I should return 10, if 33 is passed I should return 30.


Divide the number by 10, round the result and multiply it with 10 again:

var number = 33;
alert(Math.round(number / 10) * 10);