Strange result with floating point addition

前端 未结 4 1617

Why is it when I print/display the result of

eval(\"11.05\") + eval(\"-11\")

it comes out as 0.05000000000000071 instead of the expecte

4条回答
  •  悲哀的现实
    2020-12-11 23:47

    The function eval is absolutely innocent here. The culprit is floating-point operation. If you do not expect a large number of numbers after the decimal, you may limit. But you can not avoid it.

提交回复
热议问题