Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Money does automatic conversion of floats, which is extremely unhelpful #5

Closed
spookylukey opened this issue Apr 28, 2014 · 3 comments
Closed

Comments

@spookylukey
Copy link

Compare:

>>> 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.

With money, on the other hand:

>>> Money(amount='2.3', currency='GBP') * 1.2
>>> GBP 2.759999999999999897859481734

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.

@carlospalol
Copy link
Owner

I agree. I'll raise an exception.

@carlospalol
Copy link
Owner

Fixed in 12894c9 and release 1.2.0. Removed the implicit conversion. Added note in README and left Decimal to complain.

Thanks for the report.

@spookylukey
Copy link
Author

Awesome, thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants