In Python, you can round a number using the built-in round()
function. The round()
function takes two arguments: the number you want to round and the number of decimal places to round to. Here’s an example:
num = 3.14159 rounded_num = round(num, 2) print(rounded_num)
In this example, num
is the number you want to round and 2
is the number of decimal places to round to. The output will be 3.14
.
If the second argument is omitted, the round()
function will round to the nearest integer:
num = 3.7 rounded_num = round(num) print(rounded_num)
In this example, num
is 3.7
and the round()
function rounds it to 4
.