Is there a gem to cut down on big numbers like Twitter for followers?
1 answer
number_to_human
very close to what you are asking. It rounds up and down, so 410589 becomes "411 K", not sure if that's okay.
You will need either some I18n collations or a hash of units to get your suffixes, and a little tweak to get the precision you want, but for example:
opts = { units: { thousand: "K" }, precision: 0, significant: false }
number_to_human 410589, opts # => "411 K"
number_to_human 4509, opts # => "5 K"
number_to_human 349, opts # => "349"
+3
source to share