Class: NumberFormat
- Inherits:
-
Object
- Object
- NumberFormat
- Defined in:
- lib/numformat.rb
Instance Method Summary collapse
Instance Method Details
#format(number) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/numformat.rb', line 2 def format(number) if number < 1000 number.to_s elsif number < 1_000_000 n = (number / 1000.to_f).round(1) "#{n}K" else n = (number / 1_000_000-to_f).round(1) "#{n}M" end end |