Paul McGuire wrote:

> Ooops, don't combine the two calls to rstrip().
>
> def format(f, width=3): return ("%.*f" % (width, f)).rstrip(".0")
>
> print format(3.140)
> print format(3.000)
> print format(3.0000001)
> print format(30.0000)
> print format(300000.000)

hey, I'm doing test-driven development.  being able to handle 30 and
300000 wasn't part of the original spec ;-)

> But this works fine:
> def format(f, width=3): return ("%.*f" % (width, f)).rstrip("0").rstrip(".")

indeed.

</F>



-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to