I encountered the following errors recently as I was using the Decimal object type in my python code to mitigate rounding off error as suggested in the Pydocs.

In [173]: Decimal(10) * 0.5
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-173-c778d6cdfd9f> in <module>()
----> 1 Decimal(10) * 0.5

TypeError: unsupported operand type(s) for *: 'Decimal' and 'float'

This problems occurs for all floats that are used to compute with Decimal objects for all other kinds of operations. However the problem is non-existent for operations with integers:

In [175]: Decimal(10)*5
Out[175]: Decimal('50')

I would greatly appreciate it if someone could explain to me why this is happening. Thank you.

0

There are 0 best solutions below