Module: FormatHelpers
- Defined in:
- lib/helpers/format_helpers.rb
Class Method Summary collapse
-
.commarize(value) ⇒ String
Add commas to a dollar amount.
-
.format_float(price, color: nil) ⇒ String
Formats a float to 2 decimal places and the color specified.
Class Method Details
.commarize(value) ⇒ String
Add commas to a dollar amount
27 28 29 |
# File 'lib/helpers/format_helpers.rb', line 27 def self.commarize(value) value.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse end |
.format_float(price, color: nil) ⇒ String
Formats a float to 2 decimal places and the color specified
10 11 12 13 14 15 16 17 |
# File 'lib/helpers/format_helpers.rb', line 10 def self.format_float(price, color: nil) rounded = '%.2f' % price if color rounded.send(color) else rounded end end |