String formatting with floats... can't get it!

Batista, Facundo FBatista at uniFON.com.ar
Wed Mar 24 12:44:44 EST 2004


With an int:

>>> '%d' % 4
'4'
>>> '%.2d' % 4
'04'
>>> '%2d' % 4
' 4'
>>> '%2.2d' % 4
'04'


But with a float:

>>> '%f' % 2.33
'2.330000'
>>> '%.2f' % 2.33
'2.33'
>>> '%2.f' % 2.33
' 2'
>>> '%2.2f' % 2.33
'2.33'

Why in this last line I don't get ' 2.33'?

I'm using Python 2.3.3 on Linux.

Thank you!

.	Facundo




More information about the Python-list mailing list