python处理保留小数位数,包括四舍五入和不四舍五入。
import math
a = 2.3336
# 四舍五入
b = round(a,3)
b = '%.3f' % a
b = format(a, '.3f')
# 不四舍五入 math.floor只能使用取整数,下面可以变通用来处理小数
b = math.floor(a*10**3) / 10**3 # 向下
b = math.ceil(a*10**3) / 10**3 # 向上
print(type(b), b)
python处理保留小数位数,包括四舍五入和不四舍五入。
import math
a = 2.3336
# 四舍五入
b = round(a,3)
b = '%.3f' % a
b = format(a, '.3f')
# 不四舍五入 math.floor只能使用取整数,下面可以变通用来处理小数
b = math.floor(a*10**3) / 10**3 # 向下
b = math.ceil(a*10**3) / 10**3 # 向上
print(type(b), b)
ml.exe错误信息FATAL 严重错误cannot open file不能打开文件 I/O error closing fileI/O错误 正在关闭文件I/O error writing fileI/O错误 正在写文件I/O error reading file &n
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M