Reputation: 973
I have a javascript formula that rounds off the input number number
.
var number = x;
alert (Math.round(number / 10) * 10);
This will output 11,12,13,14 as 10 and 15,16,17 as 20.
This is not what I want; I want to add 1 to 10 (11) and round it up, which will return/print 20.
Example:
Upvotes: 0
Views: 516
Reputation: 696
If what I'm interpreting your question as is indeed what you're asking, then you want Math.ceil instead.
This will equate to the ceiling of the function ("rounded up", if you will)
Therefore, your code becomes:
var number = x;
alert (Math.ceil(number / 10) * 10);
Upvotes: 2