Floating point precision while using Python's max()

后端 未结 4 1387
野趣味
野趣味 2020-12-12 02:51

Why so?

>>> max(2, 2.01)
2.0099999999999998
4条回答
  •  醉酒成梦
    2020-12-12 03:26

    Floating point roundoff. Its trying to say 2.01 but can't express it exactly as a floating point number so its doing the best it can.

提交回复
热议问题