Module: MoreCoreExtensions::NumericRounding

Defined in:
lib/more_core_extensions/core_ext/numeric/rounding.rb

Instance Method Summary collapse

Instance Method Details

#round_down(nearest = 1) ⇒ Object



9
10
11
12
13
# File 'lib/more_core_extensions/core_ext/numeric/rounding.rb', line 9

def round_down(nearest = 1)
  return self if nearest == 0
  return self if (self % nearest) == 0
  self - (self % nearest)
end

#round_up(nearest = 1) ⇒ Object



3
4
5
6
7
# File 'lib/more_core_extensions/core_ext/numeric/rounding.rb', line 3

def round_up(nearest = 1)
  return self if nearest == 0
  return self if (self % nearest) == 0
  self + nearest - (self % nearest)
end