Python round() 函数

2024年9月26日 | 1 分钟阅读

Python round() 函数对数字进行四舍五入,并返回浮点数。

签名

参数

number :要进行四舍五入的数字。

digits :要对给定数字进行四舍五入的位数,这是一个可选参数。

返回

它对数字进行四舍五入,并将值作为输出返回。

让我们看一些下面给出的 round() 函数的例子

Python round() 函数示例 1

此示例显示了 Python 中 round() 函数的工作原理

输出

10
11
7

Python round() 函数示例 2

此示例将数字四舍五入到给定的 n 位小数

输出

2.67
2.67

下一个主题Python 内置函数