Last active
January 1, 2016 17:09
-
-
Save daGrevis/8175391 to your computer and use it in GitHub Desktop.
Round to number
This file contains hidden or 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
| def round_to_number(value, rounding_number): | |
| remainder = value % rounding_number | |
| rounded_down = value - remainder | |
| if remainder >= rounding_number / 2: | |
| return rounded_down + rounding_number | |
| return rounded_down | |
| assert round_to_number(1234, 500) == 1000 | |
| assert round_to_number(1250, 500) == 1500 | |
| assert round_to_number(1334, 500) == 1500 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment