In JavaScript, I would like to round a given number (x) up based on another decimal (y). For example:
x = 8.6333
y = 0.5
result = 9
x = 8.6333
y = 0.2
result = 8.8
x = 8.6333
y = 0.1
result = 8.7
How would I go about doing this?
In JavaScript, I would like to round a given number (x) up based on another decimal (y). For example:
x = 8.6333
y = 0.5
result = 9
x = 8.6333
y = 0.2
result = 8.8
x = 8.6333
y = 0.1
result = 8.7
How would I go about doing this?
Divide x by the y. Round that up, and multiply by y again.
var answer = Math.ceil(x/y)*y;