[Tutor] string formatting and right justifying text

alan.gauld@bt.com alan.gauld@bt.com
Mon, 10 Dec 2001 11:49:38 -0000


> string formatting codes to right-justify integers or floating 

%<width>.<precision><code>

Thus:

>>> print "Tot: %12.3f" % 123.45678
Tot:      123.457
>>> print "Tot: %15.2f" % 123.45678
Tot:         123.46

A negative sign left justifies:

>>> print "Tot: %-15.2f dollars" % 123.45678
Tot: 123.46         dollars

Is that what you wanted?

Alan g.