-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
normalize() method of Decimal class does not always preserve value #105774
Copy link
Copy link
Closed
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir
Description
I have encountered unexpected behavior while using the normalize() method of the Decimal class. I performed the following test using Python 3.10.10 and 3.11.4.
from decimal import Decimal
v1 = Decimal("0.99999999999999999999999999999")
v2 = v1.normalize()
print(v1) # Output: 0.99999999999999999999999999999
print(v2) # Output: 1
assert(v1 == v2) # trigger AssertionErrorBased on my understanding, the normalize() method is intended to produce a canonical representation of a decimal number. However, in this case, the values of v1 and v2 are not matching, leading to an AssertionError.
Linked PRs
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir