10
请问 Python 如何强制不使用科学计数法打印浮点数?
source link: https://www.v2ex.com/t/844824
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
有如下数据
x: float = .00000000000000000001 / 3
y: float = .0000000000000001
想要实现的输出结果:
>>> print(some_func(x))
0.000000000000000000003333333333333333
>>> print(some_func(y))
0.0000000000000001
当前输出结果:
>>> print(y)
1e-16
>>> print('%f' % y)
0.000000
>>> print('{.50f}'.format(y))
0.00000000000000009999999999999999790977867240346036
>>> print(Decimal(y))
9.999999999999999790977867240346035618411149408467364363417573258630000054836273193359375E-17
全部不满足需求。浮点数输出一个人类友好的写法有什么优雅的写法吗?目前能想到的唯一达成目标输出的方法只有将输出结果作为字符串处理,感觉很肮脏。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK