Class: Float

Inherits:
Object show all
Defined in:
lib/support/core_extensions.rb

Instance Method Summary collapse

Instance Method Details

#as_costObject



32
33
34
# File 'lib/support/core_extensions.rb', line 32

def as_cost
  self/100.0
end

#in_hundredthsObject



36
37
38
39
40
# File 'lib/support/core_extensions.rb', line 36

def in_hundredths
  return 0 if self == 0
  val = "#{self/60.0}.#{((100.0*(self.modulo(60.0)))/60.0).to_s.rjust(2, '0')}"
  BigDecimal.new(val, 2).round(2).to_f
end

#to_currencyObject



42
43
44
45
46
# File 'lib/support/core_extensions.rb', line 42

def to_currency
  int, frac = sprintf('%0.2f', self.round(2)).split('.')
  num = int.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, '\\1,')
  "$#{num}.#{frac}"
end