Why do I see a double variable initialized to some value like 21.4 as 21.399999618530273?

前端 未结 14 2003
名媛妹妹
名媛妹妹 2020-11-21 23:41
double r = 11.631;
double theta = 21.4;

In the debugger, these are shown as 11.631000000000000

相关标签:
14条回答
  • 2020-11-22 00:11

    One way you can avoid this is to use a library that uses an alternative method of representing decimal numbers, such as BCD

    0 讨论(0)
  • 2020-11-22 00:13

    If it bothers you, you can customize the way some values are displayed during debug. Use it with care :-)

    Enhancing Debugging with the Debugger Display Attributes

    0 讨论(0)
提交回复
热议问题