Created
March 16, 2015 03:03
-
-
Save chardos/1803969a223c59961779 to your computer and use it in GitHub Desktop.
dollarizing
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
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