Created
October 5, 2021 15:05
-
-
Save arnobaer/677de0f54bcc2b90eb54f527b8e89b60 to your computer and use it in GitHub Desktop.
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
import math | |
__all__ = ['round_half_away_from_zero'] | |
def round_half_away_from_zero(n: float, decimals: int = 0) -> float: | |
multiplier: float = 10 ** decimals | |
return math.copysign(math.floor(abs(n * multiplier) + 0.5) / multiplier, n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment