Module: Silverball::Numbers
- Defined in:
- lib/silverball/numbers.rb
Instance Method Summary collapse
- #fraction_as_percentage(part, full, accuracy = 1) ⇒ Object
- #number_with_separator(number, sep = "'") ⇒ Object
Instance Method Details
#fraction_as_percentage(part, full, accuracy = 1) ⇒ Object
9 10 11 12 13 |
# File 'lib/silverball/numbers.rb', line 9 def fraction_as_percentage(part, full, accuracy = 1) percentage = (part * 100.0 / full).round(accuracy) "#{ percentage }%" end |
#number_with_separator(number, sep = "'") ⇒ Object
5 6 7 |
# File 'lib/silverball/numbers.rb', line 5 def number_with_separator(number, sep = "'") number.to_s.reverse.gsub(/\d\d\d(?=\d)/) { |s| "#{ s }#{ sep }" }.reverse end |