Python中的精确舍入

Python中的精确舍入,python,precision,Python,Precision,如果某些Python代码的输出格式为“x.xx”如何提高其精度 例如: 其产量为5.5% 将其输出设为5.50000。打印(舍入)正在打印浮点值。 因此,您只需删除浮点转换: roundoffstr = "{:.5f}".format(niche+upar) print(roundoffstr) 我不太明白打印({.5f})。格式(5.5))在我的机器上打印5.50000。只需删除浮点转换:roundoffstr=“{.5f}”。格式(利基+upar);print(roundoffstr)@A

如果某些Python代码的输出格式为
“x.xx”
如何提高其精度

例如:

其产量为5.5% 将其输出设为5.50000。

打印(舍入)
正在打印浮点值。 因此,您只需删除浮点转换:

roundoffstr = "{:.5f}".format(niche+upar)
print(roundoffstr)

我不太明白<代码>打印({.5f})。格式(5.5))在我的机器上打印
5.50000
。只需删除浮点转换:
roundoffstr=“{.5f}”。格式(利基+upar);print(roundoffstr)
@AndrejKesely,
print(roundoff)
非常适合打印浮点值这是答案,只是为了补充一下,这里有一个了解格式的好资源:。f格式还有一个很酷的东西:
roundoffstr = "{:.5f}".format(niche+upar)
print(roundoffstr)