首页 > 解决方案 > 如何在 Python 中对数字进行舍入(逗号后有多个数字)

问题描述

如何打印具有 2.6000000000000001 的 2.7。(或任何其他类似的数字)。

import math

print(math.ceil(2.6000000000000001))  // 3
print(round(2.6000000000000001, 2))  // 2.6

???

标签: python-3.xmathrounding

解决方案


import math

num=2.6000000000000001
digits=1

t1=10**digits
math.ceil(num*t1)/t1

推荐阅读