Skip to content

Instantly share code, notes, and snippets.

@jaimerodas
Created May 23, 2012 04:26
Show Gist options
  • Save jaimerodas/2773269 to your computer and use it in GitHub Desktop.
Save jaimerodas/2773269 to your computer and use it in GitHub Desktop.
Simplificar numeros en JS
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