how to improve this simple block of code
Roy Smith
roy at panix.com
Wed Jan 11 09:22:29 EST 2006
In article <1136987885.792305.119640 at f14g2000cwb.googlegroups.com>,
"py" <codecraig at gmail.com> wrote:
> Say I have...
> x = "132.00"
>
> but I'd like to display it to be "132" ...dropping the trailing
> zeros...I currently try this
This sounds to me like a job for regular expressions. Something like:
re.sub (r'\.?0*$', '', x)
will do what you want. Check out the re module in the docs for more
details.
More information about the Python-list
mailing list