This very simple function does exactly what the title suggests, it allows you to round to any specified accuracy.

function roundTo(number, to) {
return Math.round(number * to) / to;
}

alert(roundTo(1532, 100)); // 1500
alert(roundTo(26, 10)); // 30

If you want to get fancy, you could also modify the Number prototype for a more “integrated” solution.

Number.prototype.roundTo = function(to) {
return Math.round(this * [...]