"Scary Math" Solver

Dave Brueck dbrueck at edgix.com
Wed Mar 14 09:49:37 EST 2001


Sorry if somebody already point this out but...

If it shakes your faith to know that many floating point numbers can't be
stored without slight rounding errors, in Python 2.1 you can always do this
to change how things work in interactive mode:

>>> 5.3
5.2999999999999998 # HELP! SAVE ME!!!
>>> def printstr(s):
>>>    print str(s)
>>> import sys
>>> sys.displayhook = printstr
>>> 5.3
5.3   # I BELIEVE!!!

And you could modify printstr so that other data types still use repr.

-Dave





More information about the Python-list mailing list