转载:Python 内建函数列表 > Python 的内置函数 round

def round(number, ndigits=None):
    '''
    求近似值

    :param number: 要计算的值
    :param ndigits: 保留的位数
    :return: 近似值
    '''

示例:

运行示例

print(round(3.1415926))
print(round(3.1415926, 2))
print(round(2.71828))
print(round(2.71828, 2))

参考:

Python官方文档-round