PEP proposal for round(x,n) enhancement
csmith at blakeschool.org
Wed Sep 12 23:01:05 CEST 2001
>The problem is that you can't store this information in a floating
>point number. I just tried the following:
>This, I give the number with 1 significant digit, and end up having
>displayed 17 "significant" digits.
Yes and no. You told Python to show you in decimal format how '0.2' is
represented as a binary number. If you had said "print 0.2" you would
obtained 0.2 and if you had said "print 0.2000" you would have obtained
thing (even though you wanted 4 significant digits). (I mentioned in a
message of this thread how you can get Python to print 0.2 for you in the
where you just type 0.2 at the IDE prompt.)
>So you may only round (or whatever we call it) to powers of two, but
>not to powers of 10 (digits) without having rationals or decimals.
Yes, you are right in that there is no way to exactly represent some
exactly as floating point numbers but this has nothing to do with rounding
number (to the closest approximation that you can) to a specific digit.
the task of the round() function. My proposal only has to do with
syntax used by the round() function.
More information about the Python-list