I donβt think that "% .3f", "% .03f" and "% 0.003f" have any difference between them, the number after the decimal point is treated as a number using the printf-family, so 3 == 03 == 003. However, "% .0f" truncates decimal places. In addition, "% .f" is different from "% f".
But the view "03" is not useless in printf-family, it fills in a zero before the number to be printed, if necessary,
>>> print "%5d" % (123) 123 >>> print "%05d" % (123) 00123 >>> print "%5d" % (123456) 123456
"% 3f" in your example does the same as "% 5d" in mine. It prints a string with a length of at least three digits. In this way,
>>> print "%3f" % (2.34567891) 2.345679 >>> print "%3.f" % (2.34567891) 2 >>> print "%3.1f" % (2.34567891) 2.3 >>> print "%3.2f" % (2.34567891) 2.35 >>> print "%3.3f" % (2.34567891) 2.346 >>> print "%30f" % (2.34567891) 2.345679 >>> print "%30.8f" % (2.34567891) 2.34567891 >>> print "%30.9f" % (2.34567891) 2.345678910
Remember, if the decimal point is omitted from the format string, the default decimal place is 6 ..
user1082599
source share