round() function strange behaviour

brobbins333 at shaw.ca brobbins333 at shaw.ca
Sat Mar 9 19:55:39 EST 2002


I knew your name was familiar! I'm reading your book right now.
It's excellent. VB for one, returns a proper rounded result on these
recalcitrant numbers. I'd be willing to bet that C can do it as well,
but you should know better than I.

The problem is that I am trying to use the return value of round() as
the return value of another function, so using Print to tidy it uup
really doesn't do me any good. Any suggestions?

BR

On Sun, 10 Mar 2002 00:16:37 GMT, Erik de Castro Lopo
<nospam at mega-nerd.com> wrote:

>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