Skip to content

Instantly share code, notes, and snippets.

@deeTEEcee
Last active August 21, 2017 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deeTEEcee/d4adc0f2a2fd9e61b0bb to your computer and use it in GitHub Desktop.
Save deeTEEcee/d4adc0f2a2fd9e61b0bb to your computer and use it in GitHub Desktop.
Ruby custom functions that could be useful
### For when you want to round up/down in custom increments of any number x (rather than just floating point rounding up to whole number)
# round_up(5, 20) -> 20
# round_up(35,20) -> 40
def round_up(num, round_by)
(num / round_by.to_f).ceil * round_by
end
# round_down(5, 20) -> 0
# round_up(35, 20) -> 20
def round_down(num, round_by)
(num / round_by) * round_by
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment