Class: Float
- Defined in:
- lib/ruby_smart/support/core_ext/ruby/float.rb,
lib/ruby_smart/support/core_ext/ruby/float.rb
Instance Method Summary collapse
-
#round_down(exp = 0) ⇒ Float
returns a new float and rounds down.
-
#round_up(exp = 0) ⇒ Float
returns a new float and rounds up.
Instance Method Details
#round_down(exp = 0) ⇒ Float
returns a new float and rounds down
14 15 16 17 |
# File 'lib/ruby_smart/support/core_ext/ruby/float.rb', line 14 def round_down(exp = 0) multiplier = 10 ** exp ((self * multiplier).floor).to_f/multiplier.to_f end |
#round_up(exp = 0) ⇒ Float
returns a new float and rounds up
32 33 34 35 |
# File 'lib/ruby_smart/support/core_ext/ruby/float.rb', line 32 def round_up(exp = 0) multiplier = 10 ** exp ((self * multiplier).ceil).to_f/multiplier.to_f end |