How to round to a multiple of a specific number JavaScript? -


this question has answer here:

i need round number nearest multiple of 27 javascript. better if round number, useful know how round closest multiple of 27 (whether or down). doesn't have vanilla javascript jquery too.

divide number 27, round (or .ceil round up) result , multiply 27:

var x = 28;  console.log('round', math.round(x/27) * 27);  console.log('ceil', math.ceil(x/27) * 27);    var y = 47;  console.log('round', math.ceil(y/27) * 27);  console.log('ceil', math.round(y/27) * 27);


Comments