2 digit after the coma pytohn 1

2 digit after the coma pytohn

"%.2f" % 1.2399 # returns "1.24"
"%.3f" % 1.2399 # returns "1.240"
"%.2f" % 1.2 # returns "1.20"

Here is what the above code is Doing:
1. The % operator takes a format string on the left and a tuple of values on the right.
2. The format string contains replacement fields surrounded by curly braces {}.
3. The values in the tuple are inserted into the replacement fields.
4. The format string and the values are passed to the str.format() method.
5. The str.format() method returns a string with the replacement fields replaced by the values.

Similar Posts