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

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -