C# float magically changing value

后端 未结 4 1197
失恋的感觉
失恋的感觉 2021-01-20 22:50


I have a float holding a very important value, which has to be VERY exact.
The problem I have is I\'m changing the value of the float ALWAYS only + and - (No divisi

4条回答
  •  感动是毒
    2021-01-20 22:56

    Float and double values are stored in binary (base 2).
    Therefore, they cannot accurately represent numbers like .3 that have no finite-length representation in binary.

    Similarly, a decimal, which is stored in base 10, cannot accurately represent numbers like 1/3 that have no finite-length representation in decimal.

    You need an arbitrary-precision arithmetic library.

提交回复
热议问题