Last active
August 27, 2019 06:22
-
-
Save OrelSokolov/e9f936b57d34c8f814a8389217338e3c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Something like Rails helper, but with short M instead of Million | |
| def short_number_to_human(n) | |
| postfix = { 1 => "", 10**3 => "K", 10**6 => "M", 10**9 => "B"} | |
| key = postfix.keys.select{|k| n/k.to_f >= 1}.max | |
| "#{(n/key.to_f).round}#{postfix[key]}" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment