This article will introduce a method to round to two decimals in Python. It is the
Round to Two Decimals Using the
round() Function in Python
We can use the built-in function
round() in Python to round to two decimal places. The correct syntax to use this function is as follows:
This function accepts two parameters. The detail of its parameters is as follows:
||mandatory||It is the
||optional||It is the number of digits that we want after the decimal point.|
The program below shows how we can use this method to round to two decimal places in Python.
myNumber = 1.237437874376 myRoundNumber = round(myNumber, 2) print(myRoundNumber)
The function has rounded the number to two decimal places.