python - np.float64 与原生 Python 浮点的 str 表示的差异
问题描述
在本机 Python类型中,当被强制转换为 afloat
时,似乎没有四舍五入:float
str
In [1]: foo = 0.24000000000000002
In [2]: print(str(foo))
0.24000000000000002
In [3]: print(repr(foo))
0.24000000000000002
但是,当np.float64
被转换为 a时str
,似乎会发生舍入。
In [4]: print(str(np.float64(foo)))
0.24
In [5]: print(repr(np.float64(foo)))
0.24000000000000002
当np.float64
被转换为 a时,舍入背后的逻辑是str
什么?
解决方案
推荐阅读
- google-apps-script - 例外:一天服务调用次数过多:gmail
- java - 如何在Java中总结两个特定日期
- ggplot2 - 如何在ggplot2中添加一个计算高于或低于某个值的点的图例?火山图
- bash - bash 脚本中的 mkdir 在文件夹名称中添加乱码
- javascript - 对以下 JS 优先级感到困惑
- java - Hibernate/SQL SERVER java.sql.SQLException:无法将 NULL 值插入具有默认值的列中
- c - 在这个计算器程序中,只有零显示为输出
- visual-studio - 重要信息级别的 PostSharp 消息未显示在 Visual Studio 错误列表中
- graphql - 为什么使用 Apollo GraphQL Sever Express(或其他集成)?
- python - 如何按顺序查找和替换偶数位置元素的值