python - String formatting with "{0:d}".format gives Unknown format code 'd' for object of type 'float' -
if understood docs correctly, in python 2.6.5 string formatting "{0:d}" same "%d" string.format() way of formatting strings
" have {0:d} dollars on me ".format(100.113) should print "i have 100 dollars on me "
however error :
valueerror: unknown format code 'd' object of type 'float'
the other format operations work.for eg.
>>> "{0:e}".format(112121.2111) '1.121212e+05'
that error signifying passing float format code expecting integer. use {0:f} instead. thus:
"i have {0:f} dollars on me".format(100.113) will give:
'i have 100.113000 dollars on me'
Comments
Post a Comment