class Numeric

Public Instance Methods

ceil_to(step, around=0) click to toggle source
# File lib/rounding/core_ext/numeric.rb, line 7
def ceil_to(step, around=0)
  whole, remainder = (self - around).divmod(step)
  num_steps = remainder > 0 ? whole + 1 : whole
  num_steps * step + around
end
floor_to(step, around=0) click to toggle source
# File lib/rounding/core_ext/numeric.rb, line 2
def floor_to(step, around=0)
  whole, _ = (self - around).divmod(step)
  whole * step + around
end
round_to(step, around=0) click to toggle source
# File lib/rounding/core_ext/numeric.rb, line 13
def round_to(step, around=0)
  whole, remainder = (self - around).divmod(step)
  num_steps = remainder*2 >= step ? whole + 1 : whole
  num_steps * step + around
end