是否有 gem 可以像 Twitter 对关注者所做的那样缩短大量数字?

Is there a gem to shorten large numbers like Twitter does for followers?

例如:

我正在寻找一种方法将非常大的数字缩短为易于阅读的格式。

number_to_human 非常接近您的要求。上下四舍五入,所以410589会变成“411K”,不知道这样可以吗

您将需要一些 I18n 映射,或者提供单位散列来获取您的后缀,并进行一些微调以获得您想要的精度,例如:

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"