Mar-05-2022, 10:11 PM
(This post was last modified: Mar-05-2022, 10:11 PM by deanhystad.)
a = f"{14.2000003:0.2f}" b = "{:0.2f}".format(14.2000003) c = "%0.2f" % 14.2000003 print(a, b, c)Which do you like best? They all work fine.
Output:14.20 14.20 14.20
I would go with the top since this is the most recent way to format. It must improve over shortcomings in the previous methods. I like how you embed the value in the same string as the formatting controls. b uses pre-3.6 Python formatting. I don't like how the values are at the end. It is easy to make a mistake on format strings with lots of values. The % formatting is ancient.