Class: Float

Inherits:
Object
  • Object
show all
Defined in:
lib/finmodeling/float_helpers.rb

Instance Method Summary collapse

Instance Method Details

#to_nearest_dollar(num_decimals = 1) ⇒ Object



20
21
22
# File 'lib/finmodeling/float_helpers.rb', line 20

def to_nearest_dollar(num_decimals=1)
  return ((self*(10.0**num_decimals)).round/(10.0**num_decimals)).to_f
end

#to_nearest_million(num_decimals = 1) ⇒ Object



14
15
16
# File 'lib/finmodeling/float_helpers.rb', line 14

def to_nearest_million(num_decimals=1)
  return (self/1000000.0*(10.0**num_decimals)).round.to_f/(10.0**num_decimals)
end

#to_nearest_thousand(num_decimals = 1) ⇒ Object



17
18
19
# File 'lib/finmodeling/float_helpers.rb', line 17

def to_nearest_thousand(num_decimals=1)
  return (self/1000.0*(10.0**num_decimals)).round.to_f/(10.0**num_decimals)
end