Python-round函数

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'>

猜你喜欢

转载自www.cnblogs.com/shuangcao/p/12047764.html