unsupported operand types for * : 'float' and 'decimal'
19,949
Solution 1
You cant multiply or devise float
and decimal.Decimal()
types, what I would suggest is multiplying by Decimal('0.0023')
and Decimal('0.5')
:
for a in range(0,size)
et = Decimal('0.0023')*ralist[rows[a][2]] * ( Decimal('0.5')*(rows[a][3] + rows[a][4]) + 17.8 ) * ( rows[a][3] - rows[a][4])**(0.5)
eto_values.insert(a,et)
Solution 2
>>> from decimal import *
>>> Decimal(1.2) * Decimal(3.4)
Decimal('4.079999999999999742428258287')
>>> Decimal(1.2) * 3.4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for *: 'decimal.Decimal' and 'float'
Author by
Admin
Updated on June 24, 2022Comments
-
Admin almost 2 years
for a in range(0,size): et = 0.0023*ralist[rows[a][2]] * ( 0.5*(rows[a][3] + rows[a][4]) + 17.8 ) * ( rows[a][3] - rows[a][4])**(0.5) eto_values.insert(a,et)
When I try to run the code, I get the following error:
unsupported operand types for * : 'float' and 'decimal'
I have tried using
decimal.Decimal()
function also. Can someone please tell me how to clear this error? -
user2357112 almost 9 years"
Decimal(0.0023)
andDecimal(0.5)
" - no! If you're going to hardcode a Decimal into your source, always construct it from a string, likeDecimal('0.0023')
, to avoid having the value rounded to what can be represented in a float. -
endolith about 6 years
devise
→divide
?