[python] How to round to 2 decimals with Python?

If you just want to print the rounded result out, you can use the f-strings introduced since Python 3.6. The syntax is the same as str.format()'s format string syntax, except you put a f in front of the literal string, and you put the variables directly in the string, within the curly braces.

.2f indicates rounding to two decimal places:

number = 3.1415926
print(f"The number rounded to two decimal places is {number:.2f}")

Output:

The number rounded to two decimal places is 3.14