Last active
August 29, 2015 13:57
-
-
Save fijimunkii/9647738 to your computer and use it in GitHub Desktop.
js: convert big numbers to abbreviations
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 format_number(n) { | |
if (n < 1000) { | |
// Anything less than a thousand | |
return parseInt(n); | |
} else if (n < 1000000) { | |
// Anything less than a million | |
return (parseInt(n / 1000) + 'K'); | |
} else if (n < 1000000000) { | |
// Anything less than a billion | |
return (parseInt(n / 1000000, 1) + 'M'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment