It Doesn't Add Up!

MRAB python at mrabarnett.plus.com
Mon Oct 12 15:17:20 EDT 2009


Victor Subervi wrote:
> Hi;
> I have the following code:
> 
[snip]
>         price = str(int(stuff[5]*100))
>         price = price[0:len(price)-2] + '.' + price[-2:]
[snip]
This is simpler:

         price = "%.2f" % stuff[5]

(not that I like what you're doing with it; leaving it as a float and
just formatting to 2 decimal places when printing it would be better!
:-))



More information about the Python-list mailing list