[Tutor] print question
Alan Gauld
alan.gauld at btinternet.com
Tue Oct 9 09:58:56 CEST 2007
"Dick Moores" <rdm at rcblue.com> wrote
> return "%02d:%02d:%2.2f" % (hours, minutes, seconds)
> print secsToHMS(4.04987) --> 00:00:4.05 (I wanted 00:00:04.05)
>
> I don't see how to get 00:00:04.05 using %f .
> <http://www.python.org/doc/2.4.1/lib/typesseq-strings.html> is as
> clear as mud.
>
%f is like this:
<justification><minimum width>.<decimal places>f
If you provide a - sign it left justifies, without a minus right
justifies
The minimum width includes the decimal point. So in your case
you want 2 + 1 + 2 = 5
decimal places is number of digits after the point
So you need:
%5.2f
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
More information about the Tutor
mailing list