You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> from decimal import Decimal
>>> Decimal("2.3") * 1.2
TypeError: unsupported operand type(s) for *: 'decimal.Decimal' and 'float'
There are extremely good reasons for this behaviour, and is one of the primary reasons that you would choose to use Decimal to represent money. A decimal library must never do a lossy conversion, and I use the Python Decimal module precisely because I can rely on it to do this correctly, and throw an exception if I ever make the mistake (and it's always a mistake) of mixing floats into my decimal calculations.
This behaviour is extremely surprising, and should instead raise an exception, the same one as above. In my opinion, with the current behaviour, this library is seriously flawed.
The text was updated successfully, but these errors were encountered:
Compare:
There are extremely good reasons for this behaviour, and is one of the primary reasons that you would choose to use Decimal to represent money. A decimal library must never do a lossy conversion, and I use the Python Decimal module precisely because I can rely on it to do this correctly, and throw an exception if I ever make the mistake (and it's always a mistake) of mixing floats into my decimal calculations.
With money, on the other hand:
This behaviour is extremely surprising, and should instead raise an exception, the same one as above. In my opinion, with the current behaviour, this library is seriously flawed.
The text was updated successfully, but these errors were encountered: