Floating numbers and str

Jeffrey Schwab jeff at schwabcenter.com
Wed Nov 9 20:49:10 EST 2005


Tuvas wrote:
> Wait, one more question. If the number is something like:
> 
> 1.32042
> 
> It is like
> "1.32 stuff"
> 
> I would like it's size to remain constant. Any way around this?

s/%g/%f

 >>> print "%.4f stuff" % 1.3241414515
1.3241 stuff
 >>> print "%.4f stuff" % 1.32042
1.3204 stuff
 >>>



More information about the Python-list mailing list