Skip to content

normalize() method of Decimal class does not always preserve value #105774

Closed
@hs-vc

Description

@hs-vc

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 AssertionError

Based 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

Metadata

Metadata

Assignees

Labels

docsDocumentation in the Doc dir

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions