Last active
April 26, 2022 19:02
-
-
Save pessini/b16498d08d3ab20e7150db918778846c to your computer and use it in GitHub Desktop.
Python uses banker’s rounding but not rounding away from zero. This function is a way to round a number away from zero (including negative numbers).
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
def round_up(x): | |
''' | |
Helper function to round away from zero | |
''' | |
from math import copysign | |
return int(x + copysign(0.5, x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment