Abs Abs - 1 year ago 81
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.

Answer Source

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

var number = 33;
alert(Math.round(number / 10) * 10);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download