Created
July 25, 2014 21:46
-
-
Save garata/ef26064eadfe8cd24546 to your computer and use it in GitHub Desktop.
Round up a number to the nearest tens
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Math.roundUp10s = (function(m) { | |
var ln10 = (m.LN10 || m.log(10)); | |
// (C) Giorgio Arata - DO WHAT YOU WANT LICENSE | |
return function roundUp10s(value) { | |
var length, power, isNeg; | |
if (isNeg = (value < 0)) | |
value = Math.abs(value); | |
length = m.floor((m.log(value) / ln10) + 1.0) - 1; | |
power = m.pow(10, length); | |
return (isNeg ? -1 : 1) * m.ceil((value) / power) * power; | |
}; | |
})(Math); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment