Created
November 4, 2017 01:54
-
-
Save a-eid/b42ce6adc7fd65ecdd9cec71f4d6bc18 to your computer and use it in GitHub Desktop.
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
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