 <pre><code> with(Math) { var exp = floor(log(number)/log(10)) - 1; exp = max(exp,0); var n = number/pow(10,exp); var n2 = ceil(n/5) * 5; var result = n2 * pow(10,exp); } </code></pre> <p><a href="http://jsfiddle.net/NvvGf/4/" rel="nofollow">http://jsfiddle.net/NvvGf/4/</a></p> <p>Caveat: only works for the natural numbers.</p>