Which C# double literal is not exactly representable as double?

后端 未结 3 1385
长发绾君心
长发绾君心 2021-01-14 10:18

Wikipedia says:

For example, the decimal number 0.1 is not representable in binary floating-point of any finite precision

Howe

3条回答
  •  囚心锁ツ
    2021-01-14 10:52

    The BCL cheats here by giving you a rounded value when you print it. There should be no literal that prints a different representation or accuracy.

    Which is nice, in that it matches intuition most of the time. But so far I haven't found a nice way of getting the exact value to print.

提交回复
热议问题