I thought this is a popular question but I have not been able to find an answer:
When square root of an integer is squared, I expect the result is an integer but I get the following:
from math import sqrt
from decimal import Decimal
a = 5
b = sqrt(Decimal(a))
c = 2 * b ** 2
print(a, c)
if c.is_integer():
print('c is integer')
do something ...
else:
print('c is NOT integer')
and the result:
5 10.000000000000002
c is NOT integer
I also tried without decimal.Decimal() but it did not work either. What is the best way to get around this? The above code is simplified for the question but I would like a generic solution if possible. I am using Python 3.5.