I am trying to perform a divide operation in python,
(3000/365)*365
which prints 3000.0000000000005. Whereas in actual this should return 3000?
Can someone help me understand what am I missing here?
I am trying to perform a divide operation in python,
(3000/365)*365
which prints 3000.0000000000005. Whereas in actual this should return 3000?
Can someone help me understand what am I missing here?
Programming languages has floting point precesion errors. which cause sometime this kind of issues.
As mentioned above, it is because of the precision when using floating points.
A solution would be to round the result:
(round(3000/365*365,2)
and if you don't want a float, you could use int
int((round(3000/365*365,2))
Not sure if there is another approach, but hope this helps.