PEP proposal for round(x,n) enhancement
csmith at blakeschool.org
Wed Sep 12 20:41:04 CEST 2001
python-list at python.org writes:
>> exactly represent such numbers. Just try
>> >>> 1/5.
>The only differnce between Python and MATLAB here is that MATLAB doesn't
>displya as many digits as Python, so you don't see that 1 on the end.
Just a note here. Python only does this when the repr() is called to
display the number. The str() function produces a more expected visual
>>> print x
>>> print `x`
Edu-sig had a way to make displayhook use str() when it prints numbers in
the IDE environment so that 0.2 would have been printed when you just
type a calculation (like 1/5. or a variable like x with no explicit
print). If you run the following code you can get this behavior:
if type(o) == type(0.1):
# print a better looking float
# remember to assign to _!
__builtin__._ = o
#use the old displayhook in every other case
(Again, this is not the reason for the proposal for the round()
enhancement but this might be useful.)
More information about the Python-list