close

[Solved] unsupported operand type(s) for *: ‘float’ and ‘Decimal’

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error unsupported operand type(s) for *: ‘float’ and ‘Decimal’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How unsupported operand type(s) for *: ‘float’ and ‘Decimal’ Error Occurs?

Today I get the following error unsupported operand type(s) for *: ‘float’ and ‘Decimal’ in python.

How To Solve unsupported operand type(s) for *: ‘float’ and ‘Decimal’ Error ?

  1. How To Solve unsupported operand type(s) for *: 'float' and 'Decimal' Error ?

    To Solve unsupported operand type(s) for *: 'float' and 'Decimal' Error It seems like self.VAT is of decimal.Decimal type and self.amount is a float, thing that you can't do.

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

    To Solve unsupported operand type(s) for *: 'float' and 'Decimal' Error It seems like self.VAT is of decimal.Decimal type and self.amount is a float, thing that you can't do.

Solution 1

It seems like self.VAT is of decimal.Decimal type and self.amount is a float, thing that you can’t do.

Try decimal.Decimal(self.amount) * self.VAT instead.

Solution 2

Your issue is, as the error says, that you’re trying to multiply a Decimal by a float

The simplest solution is to rewrite any reference to amount declaring it as a Decimal object:

self.amount = decimal.Decimal(float(amount))

and in initialize:

self.amount = decimal.Decimal('0.0')

Another option would be to declare Decimals in your final line:

return (decimal.Decimal(float(self.amount)) * self.VAT).quantize(decimal.Decimal(float(self.amount)), rounding=decimal.ROUND_UP)

…but that seems messier.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read