mirumee / prices

Python price handling for humans.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Passing float or Decimal shouldn't matter

daGrevis opened this issue · comments

I don't know for sure is this the expected behavior, but, in my opinion, this isn't right:

>>> x = Price(1.1)
>>> y = Price("1.1")
>>> x == y
False

The fix could be convert type to be str, if passed argument is float.

What do you think?

P.S. I remember that Py2.6 had something with float/Decimal. In my example I used Py2.7 thought.

Thanks!

This is expected behaviour in Python:

>>> import decimal
>>> decimal.Decimal(1.1) == decimal.Decimal('1.1')
False

Mainly because the 1.1 literal is not really 1.1:

>>> decimal.Decimal(1.1)
Decimal('1.100000000000000088817841970012523233890533447265625')

That's why we have the Decimal type.

For sure it's expected behavior in Python, but what about this library for humans? I think this is a one big place that allows you shoot yourself in foot without even knowing about it.

I'd rather raise a warning saying that you should never ever pass a float to anything even remotely touching money :)

Patch would be welcome as I'm currently away from my laptop.

Fixed in 0.4.1