Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.