fix: round negative and positive values the same way (#36242)

This commit is contained in:
Raffael Meyer 2026-02-17 06:53:37 +01:00 committed by GitHub
parent eb4b5f7973
commit f00b1b44ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1309,12 +1309,12 @@ def _bankers_rounding(num, precision):
if num == 0:
return 0.0
floor_num = math.floor(num)
floor_num = math.floor(num) if num > 0 else math.ceil(num)
decimal_part = num - floor_num
epsilon = 2.0 ** (math.log(abs(num), 2) - 52.0)
if abs(decimal_part - 0.5) < epsilon:
num = floor_num if (floor_num % 2 == 0) else floor_num + 1
num = floor_num if (floor_num % 2 == 0) else floor_num + 1 if num > 0 else floor_num - 1
else:
num = round(num)