str smarter than round?
Rainer Deyke
root at rainerdeyke.com
Fri Jun 15 13:07:26 EDT 2001
"gods1child" <alankarmisra at hotmail.com> wrote in message
news:25b2e0d9.0106150811.11efdd73 at posting.google.com...
> What does str() know that round() doesnt in the following lines?
>
> >>> a = 1.69
> >>> round(a,2)
> 1.6899999999999999
> >>> round(a,1)
> 1.7
> >>> str(a)
> '1.69'
> >>>
>
> How does str manage to get the accurate representation of floating
> points? I am using Windows 2000, Python 2.0
'str' is lying to you. The result of 'round' is displayed with 'repr',
which is more or less telling the truth.
--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games - http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
More information about the Python-list
mailing list