Created
November 25, 2014 12:40
-
-
Save guillaumepiot/4e1028076b115ab93439 to your computer and use it in GitHub Desktop.
JAVASCRIPT - Count number format
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
# Format count numbers depending on how they are: | |
# 1-999: 999 | |
# 1000+: 1K | |
# 1100+: 1.1K | |
# 10000+: 10K | |
# 100000+: 100K | |
# 1000000+: 1M | |
# 1100000+: 1.1M | |
window.format_count = (value)-> | |
if value >= 1100000 | |
return (value / 1000000).toFixed(1) + 'M' | |
if value >= 1000000 | |
return (value / 1000000).toFixed(0) + 'M' | |
if value >= 100000 | |
return (value / 1000).toFixed(0) + 'K' | |
if value >= 10000 | |
return (value / 1000).toFixed(0) + 'K' | |
if value >= 1100 | |
return (value / 1000).toFixed(1) + 'K' | |
if value >= 1000 | |
return (value / 1000).toFixed(0) + 'K' | |
return value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment