Why do simple math operations on floating point return unexpected (inaccurate) results in VB.Net and Python?

前端 未结 4 1941
误落风尘
误落风尘 2020-11-29 10:40
x = 4.2 - 0.1  

vb.net gives 4.1000000000000005
python gives 4.1000000000000005

Excel gives 4.1<

4条回答
  •  旧时难觅i
    2020-11-29 11:23

    Float/double precision.

    You must remember that in binary, 4.1 = 4 + 1/10. 1/10 is an infinitely repeating sum in binary, much like 1/9 is an infinite sum in decimal.

提交回复
热议问题