Skip to content

Instantly share code, notes, and snippets.

@garata
Created July 25, 2014 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garata/ef26064eadfe8cd24546 to your computer and use it in GitHub Desktop.
Save garata/ef26064eadfe8cd24546 to your computer and use it in GitHub Desktop.
Round up a number to the nearest tens
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