C# float magically changing value

后端 未结 4 1160
失恋的感觉
失恋的感觉 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条回答
  •  梦毁少年i
    2021-01-20 23:04

    The problem is that with float some fractional numbers cannot be exactly represented. Consider using the decimal data type if you only use + and -, you shouldn't have that problem, since decimal uses a base 10 internally.

提交回复
热议问题