[Tutor] Hummm...dubious behavior.

Jean Montambeault jrm@videotron.ca
Sat, 15 Dec 2001 02:22:45 +0200


    Felt ready for Guido's idea of a tutorial, tryed the examples, tryed
some variations, can't help it and here's something curious :

>>> tax=17.5/100
>>> price=3.50
>>> price*tax
0.61249999999999993
>>> price+_
4.1124999999999998
>>> round(_,2)
4.1100000000000003    # in this case : trailing zeros and an error
>>> ui=3.5555
>>> price*ui
12.44425
>>> round(_,2)
12.44                               # here the expectec behavior
>>> tax*ui
0.62221249999999995
>>> round(_,2)
0.62                                 # here just as well

Obviously my question is what caused the difference in behavior, when must I
expect it or best how to avoid it since, really, I can't imagine a use for
the "long" version.

Thanks gang.

Jean M.