Skip to content

Instantly share code, notes, and snippets.

@chardos
Created March 16, 2015 03:03
Show Gist options
  • Save chardos/1803969a223c59961779 to your computer and use it in GitHub Desktop.
Save chardos/1803969a223c59961779 to your computer and use it in GitHub Desktop.
dollarizing
N.howMuch.dollarize = function(num){
var l = num.toString().length;
var dollarized;
if ( l >= 1 && l <= 3 ){
dollarized = num;
}
else if ( l >= 4 && l <= 6 ){
dollarized = num.toString().substring(0, l-3) + 'K';
}
else if (l > 6 ){
dollarized = num.toString().substring(0, l-6) + 'M';
}
return '$' + dollarized;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment