扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

python中使用round函数保留小数点任意位数

扬州沐宇科技
2021-03-16 09:30:49
python, round函数

python中使用round函数保留小数点任意位数

在python中使用round()函数保留小数点任意位数的方法

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

round()函数语法:

round( x [, n] )

参数:

x:数字表达式。

n:表示需保留的小数点位数,默认值为 0。

round()函数使用方法:

print ("round(70.23456) : ", round(70.23456))

print ("round(56.659,1) : ", round(56.659,1))

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

输出结果为:

round(70.23456) : 70

round(56.659,1) : 56.7

round(80.264, 2) : 80.26

扫码添加客服微信