views:

223

answers:

2

Hello all,

My JS skills are not good enough to do the following task so I am calling on the community! I could learn to do this, but I need to get this task done quickly, so I appreciate any help.

I would like to round a number passed by a user to the nearest 10. For example, if 7 is passed I should return 10, if 33 is passed I should return 30.

I am using JQuery, I had a look for this sort of function but couldn't find one, it's too specific I guess. Hopefully, the Math library can be used?

Thanks all

+5  A: 

Divide the number by 10, round the result and multiply it with 10 again:

var number = 33;
alert(Math.round(number / 10) * 10);
Gumbo
Thank you for the explanation!
Abs
+4  A: 
Math.round(x / 10) * 10
stereofrog