Skip to content

Instantly share code, notes, and snippets.

@kahirul
Created November 28, 2012 10:33
Show Gist options
  • Select an option

  • Save kahirul/4160374 to your computer and use it in GitHub Desktop.

Select an option

Save kahirul/4160374 to your computer and use it in GitHub Desktop.
Custom ceiling
# Custom ceiling function
# Usage : If we want to ceil number by 50, it will ceil last two digit of the number into
# 0 -> 0
# (1..49) --> 50
# 50 --> 50
# (51..99) --> 100
# 123 --> 150
# Then use ceil_by_factor(number, 50)
# ceil_by_factor(123, 100) -> 200
def ceil_by_factor(num, fac)
return num + (fac + (num / fac) * fac - (num % (fac + (num / fac) * fac))) % fac
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment