Javascript using round to the nearest 10 [closed]

Solution 1:

This should do it:

Math.ceil(N / 10) * 10;

Where N is one of your numbers.

Solution 2:

To round a number to the next greatest multiple of 10, add one to the number before getting the Math.ceil of a division by 10. Multiply the result by ten.

Math.ceil((n+1)/10)*10;

1->10
2->10
3->10
4->10
5->10
6->10
7->10
8->10
9->10
10->20
11->20
12->20
13->20
14->20
15->20
16->20
17->20
18->20
19->20
20->30
21->30
22->30
23->30
24->30
25->30
26->30
27->30
28->30
29->30
30->40
35-> 40
40-> 50
45-> 50
50-> 60
55-> 60
60-> 70
65-> 70
70-> 80
75-> 80
80-> 90
85-> 90
90-> 100
95-> 100
100-> 110