Wintus
4/18/2017 - 7:10 AM

Round Up in Ruby

Round Up in Ruby

# http://stackoverflow.com/questions/3400915/how-do-i-round-an-integer-up-to-nearest-large-number-in-ruby
def round_up_10th(n)
  d = 10 ** Math.log10(n).floor
  q, r = n.divmod(d)
  m = r.zero? ? q : q.succ
  d * m
end

def round_up_2nd(n)
  d = 2 ** Math.log2(n).floor
  q, r = n.divmod(d)
  m = r.zero? ? q : q.succ
  d * m
end