C# loss of precision when dividing doubles

前端 未结 6 762
执笔经年
执笔经年 2021-01-12 07:05

I know this has been discussed time and time again, but I can\'t seem to get even the most simple example of a one-step division of doubles to result in the expected, unroun

6条回答
  •  不思量自难忘°
    2021-01-12 07:37

    It has nothing to do with how 'simple' or 'small' the double numbers are. Strictly speaking, neither 0.7 or 0.025 may be stored as exactly those numbers in computer memory, so performing calculations on them may provide interesting results if you're after heavy precision.

    So yes, use decimal or round.

提交回复
热议问题