Python 2.7 issue with decimal value 0.0

Grant Edwards invalid at invalid.invalid
Wed Mar 25 10:26:26 EDT 2015


On 2015-03-25, Larry Martell <larry.martell at gmail.com> wrote:
> I have an app that works with 2.6, but in 2.7 it is failing. I traced
> it down to an issue with decimal.Decimal being passed a value of 0.0.
> It 2.6 this is fine, but in 2.7 it throws an exception:
>
> TypeError: Cannot convert float to Decimal.  First convert the float to a string
>
> This is easy enough to deal with, but I find it odd. Is this a known issue?

$ python
Python 2.7.9 (default, Jan  2 2015, 09:51:10) 
[GCC 4.8.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
>>> decimal.Decimal(0)
Decimal('0')
>>> decimal.Decimal(0.0)
Decimal('0')
>>> decimal.Decimal('0')
Decimal('0')
>>> 


-- 
Grant Edwards               grant.b.edwards        Yow! Half a mind is a
                                  at               terrible thing to waste!
                              gmail.com            



More information about the Python-list mailing list