I'm having an issue with determining if a variable is an integer. Not the variable type, but the actual value stored in the variable. I have tried using variable % 1
as a test, but it does not seem to work. Here is the code I'm using for the test:
if ((xmax - x0)/h) % 1 == 0:
pass
elif ((xmax - x0)/h) % 1 != 0:
print "fail"
No matter what values are present for xmax, x0, and h, the statement always passes. For example, if they are 2.5 (2.5 % 1 = .5), it will still pass. I have tried if/else so i tried an else if statement as above and it does not work either.
int(x) == x
– MostafaR May 16 '13 at 4:52