Last active
August 21, 2017 20:59
-
-
Save deeTEEcee/d4adc0f2a2fd9e61b0bb to your computer and use it in GitHub Desktop.
Ruby custom functions that could be useful
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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