Rounding curiosity
Ganesan R
rganesan at myrealbox.com
Tue Nov 16 23:39:10 EST 2004
>>>>> "Tim" == Tim Peters <tim.peters at gmail.com> writes:
> What's wrong is that you haven't yet read the Python tutorial's
> appendix on floating-point issues. That much is easily repaired
> <wink>:
> http://docs.python.org/tut/node15.html
IMHO the documentation for round() function is misleading in this
respect. It reads
====
round(x[, n])
Return the floating point value x rounded to n digits after the decimal
point. If n is omitted, it defaults to zero. The result is a floating
point number. Values are rounded to the closest multiple of 10 to the
power minus n; if two multiples are equally close, rounding is done away
from 0 (so. for example, round(0.5) is 1.0 and round(-0.5) is -1.0).
====
Something like, "Note that, since the floating point values cannot represent
decimal fractions exactly, the rounding will not be exact." should help.
Ganesan
More information about the Python-list
mailing list