Formatting numbers

Fredrik Lundh fredrik at pythonware.com
Wed May 2 02:10:15 CEST 2001


Daniel Klein wrote:
> Given an integer, 12345, how to format this to 123.45 ?

> Ok, this is what I've come up with so far
>
>     x = 12345
>     print '%.2f' % (x,)

you don't have to "tuplify" a single value, but tuple
or not, it doesn't really work as specified:

>>> print "%.2f" % (x,)
12345.00
>>> print "%.2f" % x
12345.00

Cheers /F





More information about the Python-list mailing list