# Re: 1== 1 is False?

Discussion in 'Python' started by Curly Joe, Jun 25, 2003.

1. ### Curly JoeGuest

Not sure what you mean by more exactness, and why
rounding wouldn't work as in
x = 2.260212
y = 2.260212
print "%f and %f are " % (x, y),
##--- round to 3 digits
if round(x, 3) == round(y, 3) :
print "Equal to 3 decimals"
else :
print "Not Equal"

x += 0.000001
print "%f and %f are " % (x, y),
if round(x, 3) == round(y, 3) :
print "Equal to 3 decimals"
else :
print "Not Equal"

This prints:
2.260212 and 2.260212 are Equal to 3 decimals
2.260213 and 2.260212 are Equal to 3 decimals

This is one of the things that we have to learn to
live with in a binary number system as far a I know,
just like we have to truncate/round numbers like 10/3
or 10/6 in our base 10 system.

> > What do i have to do, if i need "more" exactness?
> > I have for example the problem with the

> representation of 2.3 or 2.
> 7:
> > >>> 2.3

> > 2.2999999999999998
> > >>> 2.7

> > 2.7000000000000002
> > This is a really strange behaviour!
> >
> > Thomas
> > --

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only \$29.95 per month!
http://sbc.yahoo.com

Curly Joe, Jun 25, 2003