Class: Fixnum
- Inherits:
-
Object
- Object
- Fixnum
- Defined in:
- lib/finmodeling/float_helpers.rb
Instance Method Summary collapse
- #to_nearest_dollar(num_decimals = 1) ⇒ Object
- #to_nearest_million(num_decimals = 1) ⇒ Object
- #to_nearest_thousand(num_decimals = 1) ⇒ Object
Instance Method Details
#to_nearest_dollar(num_decimals = 1) ⇒ Object
8 9 10 |
# File 'lib/finmodeling/float_helpers.rb', line 8 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
2 3 4 |
# File 'lib/finmodeling/float_helpers.rb', line 2 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
5 6 7 |
# File 'lib/finmodeling/float_helpers.rb', line 5 def to_nearest_thousand(num_decimals=1) return (self/1000.0*(10.0**num_decimals)).round.to_f/(10.0**num_decimals) end |