>> how can I suppress the decimal places for (only those) numbers whos
>> decimal places are zero (0)?
>
> I don't know how to do this with just string formatting but I think
> ('%.4f' % n).rstrip('.0')
> will do what you want.
No.
I tested with
n = 10.0
You code returns '1'
My code returns '10'
Here again:
### CODE ###
def cut_decimals(float):
"""
input: floating number
output: number as string with zero decimals removed
"""
#print float-int(float)
#print '%.4f' %float
if float-int(float) != 0:
number = '%.4f' %float
number = number.replace('0.','X.')
number = number.replace('0','')
number = number.replace('X.','0.')
else:
number = '%.0f' %float
return number
#### END ###
Regards,
Timmie
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor