javascript - Round to nearest multiple with offset in JS -


i have number want round nearest multiple of x with offset. example, how round number nearest number 5 more multiple of 12 (ie 5, 17, 29...)?

in case it'd this:

var input = 34; var offset = 5; var multiple = 12; var result = (math.round((input - offset) / multiple) * multiple) + offset; 

this should find nearest number 34 5 more multiple of 12 (29)


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -