Class: Float

Inherits:
Object
  • Object
show all
Defined in:
lib/forgeos/commerce/float.rb

Instance Method Summary collapse

Instance Method Details

#decimal(precision = 2) ⇒ Object



2
3
4
# File 'lib/forgeos/commerce/float.rb', line 2

def decimal(precision = 2)
  ((self % 1) * (10 ** precision)).round
end

#diff(number) ⇒ Object



6
7
8
9
# File 'lib/forgeos/commerce/float.rb', line 6

def diff(number)
  return 0 if number.zero?
  (((self - number) / number)* 100).round
end