Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

problem with float not equals but should be equals? problem

Dear Collegues

I have a problem with checking equals float numbers: code:

d = 0.2
u = d - 1
up = d - 0.5
r = u

for i in range(1,7):
    r = r + 0.1
    print(i,r,up)
    if r == up :
        print("equal","r",r,"=","up",up)
        break;

output:

1 -0.700000000000000 -0.300000000000000
2 -0.600000000000000 -0.300000000000000
3 -0.500000000000000 -0.300000000000000
4 -0.400000000000000 -0.300000000000000
5 -0.300000000000000 -0.300000000000000
6 -0.200000000000000 -0.300000000000000

in line 5 -> it should print that are equals... what is wrong?