Python中取小数用什么函数

1327
2021/1/26 12:53:11
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

Python中取小数用什么函数

Python中使用round函数取小数,具体方法如下:

round:round()函数的作用是回浮点数x的四舍五入值。

round()函数语法:

round( x [, n] )

参数:

x :数值表达式。

n :数值表达式,表示从小数点位数。

round()函数使用方法:

print "round(80.23456, 2) : ", round(80.23456, 2)

print "round(100.000056, 3) : ", round(100.000056, 3)

print "round(-100.000056, 3) : ", round(-100.000056, 3)

输出结果为:

round(80.23456, 2) : 80.23

round(100.000056, 3) : 100.0

round(-100.000056, 3) : -100.0

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: python serial库安装的方法是什么