pythons round() behaves unexpected (for me at least)

This commit is contained in:
Stefan Harmuth 2021-12-28 11:49:14 +01:00
parent 4880c1bee2
commit 5df8926378

7
tools/math.py Normal file
View File

@ -0,0 +1,7 @@
from decimal import Decimal, ROUND_HALF_UP
from .types import Numeric
def round_half_up(number: Numeric) -> int:
""" pythons round() rounds .5 to the *even* number; 0.5 == 0 """
return int(Decimal(number).to_integral(ROUND_HALF_UP))