In Python 3, when I multiply an integer with a float, using a function or directly, I get a wrong answer.
def mult(a,b):
c= a*b
return c
mult(10,3.14)
The answer I obtain is 31.400000000000002
.
When I tried typecasting the integer value as float as in direct multiplication
a=float(10)
b=3.14
c=a*b
c
I still get the same answer.
Meanwhile, mult(7,3.2)
provides an answer of
22.400000000000002
.
screenshot of second multiplication
How do I fix this?
Edit: I agree that a similar question was asked earlier. But, before asking this question, I didn't find that similar question when searched in Google or in stack overflow. Different people use different search queries to search for the same query. So, in my opinion, this question should not be deleted and should stay.