python-3.x - 如何在 Python 中对数字进行舍入(逗号后有多个数字)
问题描述
如何打印具有 2.6000000000000001 的 2.7。(或任何其他类似的数字)。
import math
print(math.ceil(2.6000000000000001)) // 3
print(round(2.6000000000000001, 2)) // 2.6
???
解决方案
import math
num=2.6000000000000001
digits=1
t1=10**digits
math.ceil(num*t1)/t1
推荐阅读
- react-native - 当变量发生变化时反应原生调用 useEffect
- javascript - 第一次迭代后 for 循环中的 Cypress 元素发生变化
- python - 用于 RSA 公开解密的 Python 库
- spring-boot - Spring Boot 中的后备消息文件始终为“en”
- git - 如何将推送的常规合并转换为 git 中的 squash-merge?
- javascript - 如何在 JavaScript 网站中转换我的 Kotlin 应用程序?
- firebase - Read single document field from Firestore (Flutter)
- python - 在 Flask/SQLAlchemy 中选择性地对 InstrumentedAttribute 执行数学计算
- sql - SQL连接查询,想获取连接表的最新记录(不匹配则为null)
- angular - 离子预览pdf文件