python 小数保留位数

利用round(number[, ndigit] )函数四舍五入

保留浮点数的小数点。

     如保留小数点后两位。

     num = 9.2174

     new_num = round( num , 2 )

     则new_num = 9.22    (四舍五入)
>>> num = 4.93
>>> num
4.93
>>> new_num = round(num,0)
>>> new_num
5.0
>>> num = 4.49
>>> new_num = round(num,0)
>>> new_num
4.0
>>> new_num = round(num,0)
原文地址:https://www.cnblogs.com/shenckicc/p/6938571.html