javascript - How can I round a decimal up to the nth decimal? -
in javascript, round given number (x) based on decimal (y). 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 go doing this?
divide x y. round up, , multiply y again.
var answer = math.ceil(x/y)*y;
Comments
Post a Comment