round()

The built-in function that rounds a number to a given number of decimal places, returning a new number.

In more detail

round(2.675, 2) gives 2.67, not 2.68, because the float is really slightly below 2.675, and exact halves round to the even neighbour. Round the value only when you need the rounded number; to change only what is shown, use a format specifier.

Example

round(3.14159, 2)   # 3.14

Related terms

Taught in

References

Certification courses