码迷,mamicode.com
首页 > 其他好文 > 详细

round方法

时间:2020-03-18 17:09:58      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:情况   code   参数   有一个   int   一个   too   gif   保留   

round函数:对给定的数进行四舍五入,只有一个参数的情况下,是将其四舍五入后为整型,第二个参数是保留几位小数

技术图片
1 a = round(2.523456)
2 print(a)
3 print(‘a的类型‘,type(a))
4 b =round(2.523456,1)
5 print(b)
6 print(‘b的类型‘,type(b))
7 c =round(2.523456,2)
8 print(c)
9 print(‘c的类型‘,type(c))
技术图片

结果:

3
a的类型 <class ‘int‘>
2.5
b的类型 <class ‘float‘>
2.52
c的类型 <class ‘float‘>

round方法

标签:情况   code   参数   有一个   int   一个   too   gif   保留   

原文地址:https://www.cnblogs.com/baoshilin/p/12518477.html

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