相关疑难解决方法(0)

在Python中使用"Decimal"

有人可以解释下面发生的事情:(我使用Python 3.3)

1. >>> Decimal("0.1") + Decimal("0.1") + Decimal("0.1") - Decimal("0.3")
       Decimal('0.0')

2. >>> Decimal(0.1) + Decimal(0.1) + Decimal(0.1) - Decimal(0.3)
       Decimal('2.775557561565156540423631668E-17')

3. >>> Decimal(0.1 + 0.1 + 0.1 - 0.3)
       Decimal('5.5511151231257827021181583404541015625E-17')
Run Code Online (Sandbox Code Playgroud)

我知道它与浮点限制有关,如果有人可以解释原因,我会很高兴

  • 什么有" "要做的实例1和2以上的区别
  • 鉴于两者都没有,为什么2会产生3的差异答案" "

python decimal-point python-3.x

2
推荐指数
1
解决办法
2172
查看次数

标签 统计

decimal-point ×1

python ×1

python-3.x ×1