round() function strange behaviour
Erik de Castro Lopo
nospam at mega-nerd.com
Sat Mar 9 19:16:37 EST 2002
brobbins333 at shaw.ca wrote:
>
> I understand the problem of rounding errors with binary numbers.
> However, the rounding functions of other languages work around it and
> return a usable result. What have they got that Python hasn't got?
Possibly other scripting languages have a feature which includes the
current printing representation with the floating point object. This
would however surprise me somewhat.
Have you tried that specific example with other languages? I looked
at Perl and it doesn't have a round function. Apparently the preferred
method in Perl is sprintf ("%.2f", 56.78923) which returns a string
instead of a float.
Once a float is represented as a string you get the behviour you are
after.
> ps -- your name is very familiar. i think i've read one of your books.
I only have one, "SAMs Teach yourself C for Linux Programming in 21 days".
I also have a couple of Free Software packages out there.
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo nospam at mega-nerd.com (Yes it's valid)
+-----------------------------------------------------------+
"If dolphins are so smart, why do they live in igloos?" -Eric Cartman
More information about the Python-list
mailing list