Python 2.7 issue with decimal value 0.0

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Mar 25 10:29:38 EDT 2015


On 25 March 2015 at 14:20, 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?

Perhaps I've misunderstood but decimal.Decimal(0.0) works fine here:

$ python2.7
Python 2.7.3 (default, Dec 18 2014, 19:10:20)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
>>> decimal.Decimal(0.0)
Decimal('0')


Oscar



More information about the Python-list mailing list