Float precision with specific numbers

前端 未结 3 945
逝去的感伤
逝去的感伤 2021-01-26 05:31

The following value gives me wrong precision. It is observed with only specific numbers. It might be a floating representation problem, but wanted to know the specific reason.

3条回答
  •  情书的邮戳
    2021-01-26 06:06

    Float offers a base 2 representation of a decimal number. When you parse, it is parsing the binary representation of the decimal number that will almost never be exact. You may get .4856 from its binary representation (well, I didn't do the calculation and its just a guess to get you the idea).

提交回复
热议问题