Abs - 4 months ago 13

Javascript Question

Using Javascript, 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.

Answer

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

```
var number = 33;
alert(Math.round(number / 10) * 10);
```