cdecimal.Decimal v. decimal.Decimal

Ian Kelly ian.g.kelly at gmail.com
Tue Jun 20 17:11:36 EDT 2017


On Tue, Jun 20, 2017 at 2:49 PM, Skip Montanaro
<skip.montanaro at gmail.com> wrote:
> I'd not used the Decimal classes before, but some data I was receiving
> from a database via pyodbc came that way. In writing some test cases,
> I had a hard time making things work out. I eventually figure out what
> was going on:
>
>>>> import decimal, cdecimal
>>>> decimal.Decimal('2226.48') == cdecimal.Decimal('2226.48')
> False
>
> (apologies for any typos, can't copy/paste)
>
> This seems odd to me. I'm currently unable to make the comparison in
> my Python 3 env (Conda woes), but I have both decimal and cdecimal in
> my Python 2.7 env. Shouldn't these beasts compare equal?

It seems like it, although I don't think they were ever intended to be
used side-by-side. cdecimal isn't part of the standard library and is
supposed to be a drop-in replacement. As of CPython 3.3, the decimal
module *is* cdecimal.



More information about the Python-list mailing list