【发布时间】:2022-06-11 02:51:50
【问题描述】:
我的目标是在 Python 中准确地从 18 位小数的值中添加或删除 0.05%,而不将它们转换为浮点数。我提出了以下两个解决方案,它们对我来说似乎是正确的,但我对 Python 中的数字非常不熟悉,因此我想知道是否有更好的(就准确性而言)解决方案。
price_in_wei = 1000000000000000000 # = 1
# -0.05%
price_with_fee = (price_in_wei/1000)*995
# +0.05%
price_with_fee = (price_in_wei/1000)*1005
# -0.05%
price_with_fee = (price_in_wei*995)/1000
# +0.05%
price_with_fee = (price_in_wei*1005)/1000
【问题讨论】:
-
只是好奇您的准确度阈值是多少?精确到 18 位十进制数字?
标签: python