In Python, you can round a number to 2 decimal places using the round()
function. Here’s how:
Using the round()
Function:
python
number = 123.456789
# Round to 2 decimal places
rounded_number = round(number, 2)
print(rounded_number)
Explanation:
round(number, 2)
rounds thenumber
to 2 decimal places.
This is a simple and efficient way to round numbers to a specific number of decimal places in Python.