Created
May 23, 2012 04:26
-
-
Save jaimerodas/2773269 to your computer and use it in GitHub Desktop.
Simplificar numeros en JS
This file contains 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
function numeroSimple(d) { | |
p = 100; // La base que usaremos | |
var a = [ "K", "M", "B", "T" ]; // Las abreviaturas | |
for (var i=a.length-1; i>=0; i--) { | |
var l = Math.pow(10, (i+1)*3); | |
if(size <= d) { | |
d = Math.round(d*p/l)/p; | |
d += a[i]; | |
break; | |
} | |
} | |
return d; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment