Rounding curiosity

Donn Cave donn at
Wed Nov 17 19:18:36 CET 2004

In article <419ad276$0$1581$a1866201 at>,
 Grant Edwards <grante at> 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

More information about the Python-list mailing list