Class: Object

Inherits:
BasicObject
Defined in:
lib/commercebank/monkey.rb

Instance Method Summary collapse

Instance Method Details

#to_centsObject



23
24
25
# File 'lib/commercebank/monkey.rb', line 23

def to_cents
  (to_s.gsub(/[^-.0-9]/, '').to_f * 100).to_i
end

#to_dollars(*options) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/commercebank/monkey.rb', line 27

def to_dollars(*options)
  options = options.paramify

  plus = options[:show_plus] ? '+' : ''
  minus = options[:hide_minus] ? '' : '-'
  sign = to_i >= 0 ? plus : minus

  ("%s%0.2f" % [ sign, to_i.abs / 100.0 ]).commify
end