Rounding curiosity

Donn Cave donn at u.washington.edu
Wed Nov 17 13:18:36 EST 2004


In article <419ad276$0$1581$a1866201 at visi.com>,
 Grant Edwards <grante at visi.com> wrote:
...
> If you're just worried about how it looks on the screen:
> 
> >>> print "%0.2f" % round(5e8/(1024*1024),2)
> 476.84
> 
> If you want the computer to fib for you, it will. :)

Actually it will anyway - once you use "print", you
get a str() automatically, and that rounds off in a
way that happens to give you the same result in this
case - so the formatting above is superfluous unless
the occasional trailing zero is important.  If repr()
did the same, we'd hear a lot less of this.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list