control precision for str(obj) output?

Bo Peng bpeng at rice.edu
Wed May 4 03:34:50 CEST 2005


Dear list,

I have enjoyed the convenience to output any object with str(obj) for a 
while. However, I get long output for things like str([0.0002]) in my 
output (which bothers my users more than me though). I also do not 
understand why the following is happening:

 >>> str([0.0002])
'[0.00020000000000000001]'
 >>> str(0.0002)
'0.0002'

Is there any way to fix this, other than checking the type of everything 
and output with %.4f?

Many thanks in advance.
Bo



More information about the Python-list mailing list