how to improve this simple block of code

py codecraig at gmail.com
Wed Jan 11 14:58:05 CET 2006


Say I have...
x = "132.00"

but I'd like to display it to be "132" ...dropping the trailing
zeros...I currently try this

if x.endswith("0"):
    x = x[:len(x)-1]
if x.endswith("0"):
    x = x[:len(x)-1]
if x.endswith("."):
    x = x[:len(x)-1]

I do it like this because if
x = "132.15"  ...i dont want to modify it.  But if
x = "132.60" ...I want it to become "132.6"

is there a better way to do this?  It seems a bit ugly to me.

T.I.A
(thanks in advance)




More information about the Python-list mailing list