码迷,mamicode.com
首页 > 编程语言 > 详细

python 小数保留位数

时间:2017-06-03 22:33:42      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:log   小数点   pre   pytho   5.0   bsp   4.0   blog   git   

利用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)

 

python 小数保留位数

标签:log   小数点   pre   pytho   5.0   bsp   4.0   blog   git   

原文地址:http://www.cnblogs.com/shenckicc/p/6938571.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!