The following table shows a variety of ways to format numbers with Python's rookie str.format(), including examples of floating-point number formatting and integer formatting. You can use print("FORMAT".format(NUMBER)); to run the example, so you can run: print("{:.2f}".format(3.1415926)); to get the output of the first example.
Number | Format | Output | Description |
---|---|---|---|
3.1415926 | {:.2f} | 3.14 | Two decimal places |
3.1415926 | {:+.2f} | +3.14 | Two decimal places with signs |