Skip to content

Instantly share code, notes, and snippets.

@arnobaer
Created October 5, 2021 15:05
Show Gist options
  • Save arnobaer/677de0f54bcc2b90eb54f527b8e89b60 to your computer and use it in GitHub Desktop.
Save arnobaer/677de0f54bcc2b90eb54f527b8e89b60 to your computer and use it in GitHub Desktop.
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