Steven D'Aprano wrote: > Here is a (quick and dirty) reference implementation: > > def format(f, width=3): > fs = '%%.%df' % width > s = fs % f > return s.rstrip('0').rstrip('.') > > Is there a way of getting the same result with just a > single string format expression?
not with % itself, but you can do it all in one line: def format(f, width=3): return ("%.*f" % (width, f)).rstrip(".0") </F> -- http://mail.python.org/mailman/listinfo/python-list