This is actually just a modification from JavaScript Round To Nearest Number by Talk in Code. Instead of getting the nearest digit, we will actually get the rounding to the next nearest number.
function roundNextNearest(num, acc) {
if ( acc < 0 ) {
return Math.round(num*acc)/acc;
} else {
var value = Math.round(num/acc)*acc;
if (value < num) {
value += acc;
}
}
return value;
}



Recent Comments