Class: Float
- Inherits:
-
Object
- Object
- Float
- Defined in:
- lib/functional_support/core_ext/float.rb
Instance Method Summary collapse
Instance Method Details
#round_to_nearest(n = 1) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/functional_support/core_ext/float.rb', line 3 def round_to_nearest(n=1) how_many_ns = (self / n) complete_ns = how_many_ns.to_i partial_ns = how_many_ns - complete_ns if partial_ns >= 0.5 (complete_ns + 1) * n else complete_ns * n end end |