Rounding a number up to it’s nearest order of ten

I’m hopeless at math, this is just for future reference as it really bugged me. How to round a number up to it’s upper orderĀ of 10. Not a simple as it may seem.

Examples:

800 -> 1000
125 -> 1000
80 -> 100
43 -> 100
8 -> 10
9 -> 10
0.8 -> 1
0.23 -> 1
.08 -> 0.1
(consider -> to be “goes-to” or “rounds-up-to”)

 

The solution

Here’s the equation that solves it:

10^(ceil(log10(x))) (ref: stackoverflow)

 

Here’s a worked JSFiddle:

http://jsfiddle.net/jralston/rjuL5o8v/