Re: 1== 1 is False?

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

  1. Curly Joe

    Curly Joe Guest

    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
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. André
    Replies:
    3
    Views:
    1,557
  2. Rajarshi

    0 == False but [] != False?

    Rajarshi, May 24, 2007, in forum: Python
    Replies:
    20
    Views:
    685
    Erik Max Francis
    May 30, 2007
  3. DJ
    Replies:
    3
    Views:
    906
  4. trans.  (T. Onoma)
    Replies:
    0
    Views:
    138
    trans. (T. Onoma)
    Sep 25, 2004
  5. trans.  (T. Onoma)
    Replies:
    1
    Views:
    159
    David A. Black
    Sep 25, 2004
Loading...

Share This Page