Search code examples
ruby-on-railslayoutrating

10K, 20M, 21V kudos etc... in Ruby on Rails


I am creating a snippet-site where people can rate snippets, just like votes on SO. Currently, when a snippet has over 999 kudos, it looks like on this mug: mug
(source: picocool.com)

So what I want is to do a 1K, 1M, etc... kudos like on SO:

-----
|999|
-----

**user does +1**
-----
|1K |
-----

**one million kudos**
-----
|1M |
-----

The same goes for billions, trillions, quadrillions, quintillions, etc... :'D

Has Ruby got methods for this, and if not, how can I write them myself? Thanks.


Solution

  • I don't think Ruby has something like this. Rails does have a set of number helpers, but doesn't include this specific feature. However, if you view source for "number to human size" you should be able to roll your own without much trouble.