I\'ve checked out Rails number_to_human but it\'s not exactly what i want.
I\'d like to shorten long numbers without including the full unit name:
42
Put in your config/locales/en.yml
:
en:
number:
human:
decimal_units:
format: "%n%u"
units:
unit: ""
thousand: K
million: M
billion: B
trillion: T
quadrillion: Q
Then you'll get:
number_to_human 420 # => "420"
number_to_human 5680 # => "5.68K"
number_to_human 12680 # => "12.7K"
number_to_human 6802251 # => "6.8M"
number_to_human 894100158 # => "894M"
Like this:
number_to_human(a_number,format:'%n%u',units:{thousand:'K',million:'M',billion:'B'})