search

What is the use of the "round" function in Python?

The **round** function in Python is used to round a floating-point number to a specified number of decimal places. The rounded value is returned as a float. The basic syntax for the **round** function is:

round(number, ndigits)

where **number** is the floating-point number to be rounded, and **ndigits** is the number of decimal places to round to. If **ndigits** is not specified, the number is rounded to the nearest whole number. The **round** function uses "round half to even" or "bankers' rounding" by default, which rounds to the nearest even number if the fractional part is exactly 0.5.

Related Questions You Might Be Interested