Are Double constants truncated for display in VS?

試著忘記壹切 提交于 2019-12-08 19:43:59

问题


The constant Math.Pi is, according to reflector and MSDN, equal to 3.14159265358979323846. When looking at the Math class in Visual Studio 2010, the value is displayed as 3.14159. Whom can I blame for truncating precious constants?


回答1:


I don't know why the OP isn't posting this, as it would clear things up so incredibly much, but you can reproduce as follows:

  • Open the IDE
  • Enter Math.PI into a .cs file.
  • Right-click on Math.PI and click on 'Go To Definition'

This opens up the Metadata file for Math, which contains the following:

    //
    // Summary:
    //     Represents the ratio of the circumference of a circle to its diameter, specified
    //     by the constant, π.
    public const double PI = 3.14159;



回答2:


Sorry to repeat myself, but how do you get that number? If I hover over the constant or print it in the Immediate or Watch window in VS2010, I get 3.1415926535897931, which is also the value I get when looking at mscorlib in Reflector.

While it is less precision than MSDN claims, it is still far better than the number you're talking about. VS has to pick a formatting for printing floating point numbers. With the results I see I find the default quite acceptable.




回答3:


You can blame the VS metadata view, which is what you get when you press F12 on something you don't have the source to.

At least I presume that's what you're doing, because it's the only place I can find the truncated constant you're talking about.

Why does it do it / where does it get that value from? Who knows...




回答4:


Maybe you have a plugin for VS 2010 that is changing the output of the number. Or maybe you're displaying the number in a display context that has to truncate the number to fit. Where exactly in Visual Studio are you viewing this number?



来源:https://stackoverflow.com/questions/3742753/are-double-constants-truncated-for-display-in-vs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!