Skip to content

Instantly share code, notes, and snippets.

@fijimunkii
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fijimunkii/9647738 to your computer and use it in GitHub Desktop.
Save fijimunkii/9647738 to your computer and use it in GitHub Desktop.
js: convert big numbers to abbreviations
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