Skip to content

Instantly share code, notes, and snippets.

@a-eid
Created November 4, 2017 01:54
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 a-eid/b42ce6adc7fd65ecdd9cec71f4d6bc18 to your computer and use it in GitHub Desktop.
Save a-eid/b42ce6adc7fd65ecdd9cec71f4d6bc18 to your computer and use it in GitHub Desktop.
window.formatWithSuffix = function(input){
suffixes = ['', 'k', 'm', 'g', 't'];
suffixIndex = 0;
while( Math.abs(input) >= 1000 && suffixIndex < suffixes.length ){
suffixIndex++;
input /= 1000;
}
return (
input > 0
? Math.floor( input * 1000) / 1000
: Math.ceil( input * 1000) / 1000
)
+ suffixes[suffixIndex];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment