Dick Moores <rdm <at> rcblue.com> writes: > So now that I know better, I'm trying to write the beginnings of a > general setPrecision() function using format strings. However, it > appears that a variable cannot be used instead of the ".2" in > > "%.2f" % 2.234234 <snip> > How to do this?
http://www.python.org/doc/current/lib/typesseq-strings.html >>> "%.*f" % (2, 2.234234) '2.23' >>> "%.*f" % (3, 2.234234) '2.234' >>> "%.*f" % (1, 2.234234) '2.2' >>> "%.*f" % (0, 2.234234) '2' _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor