Class: NumberFormat
- Inherits:
-
Object
- Object
- NumberFormat
- Defined in:
- lib/cient_notation.rb
Instance Method Summary collapse
Instance Method Details
#format(number) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/cient_notation.rb', line 2 def format(number) digits = number.to_s.size case digits when 1..3 "#{number}" when 4..6 "#{(number/1000.0).round(1)}K" when 7..9 "#{(number/1000000.0).round(1)}M" end end |