[Pythonmac-SIG] Re: Number format in IDE
Christopher Smith
csmith@blakeschool.org
Sun, 26 Aug 2001 12:23:35 -0500
>>Is there any way to change the default number format in the IDE? It is
>>disturbing to show students x=5.1, x+2=7.00000000000000000000012 or some
>>such thing. Is it possible to set the default number of decimal places to
>>something like 4, so that things look nicer when using Python as a
>>calculator?
>Hmm... I obtain the following results which show that STR() is
>a kinder presenter than `...` when it comes to showing the numbers.
>If the IDE could be made to use STR instead of REPR maybe this would
>help. I don't know how to do that, however.
>
>>>> 5.1+2
>7.0999999999999996
>>>> print str(5.1+2)
>7.1
>>>> print `5.1+2`
>7.0999999999999996
>>>>
OK, so the fix is to explicitly "print" what you want to see
rather than letting Python show you the result:
Python 2.1.1 (#97, Aug 2 2001, 21:53:31) [CW PPC GUSI2 THREADS]
Type "copyright", "credits" or "license" for more information.
>>> x=5.1
>>> y=2
>>> print x+y #this is the explicit print and it looks nice
7.1
>>> x+y #this is NOT an explicit print and is ugly as you note
7.0999999999999996
/c