Double 常量在 VS 中显示时是否会被截断?
根据 Reflector 和 MSDN,常量 Math.Pi 等于 3.14159265358979323846。在 Visual Studio 2010 中查看 Math 类时,该值显示为 3.14159。我该责怪谁截断了宝贵的常数呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道为什么 OP 没有发布这个,因为它会让事情变得非常清楚,但你可以按如下方式重现:
这将打开 Math 的元数据文件,其中包含以下内容:
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:
This opens up the Metadata file for Math, which contains the following:
很抱歉重复一遍,但是您如何获得该号码?如果我将鼠标悬停在常量上或在 VS2010 的“立即”或“监视”窗口中打印它,我会得到 3.1415926535897931,这也是我在 Reflector 中查看 mscorlib 时得到的值。
虽然它的精度低于 MSDN 声称的精度,但它仍然比您所说的数字要好得多。 VS 必须选择一种打印浮点数的格式。从结果来看,我发现默认值是可以接受的。
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.
你可以责怪 VS 元数据视图,这是当你在没有源代码的东西上按 F12 时所得到的。
至少我认为这就是你正在做的事情,因为这是我可以找到你正在谈论的截断常量的唯一地方。
它为什么这样做/它从哪里获得这个值?谁知道...
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...
也许您有一个 VS 2010 插件可以更改数字的输出。或者,您可能在显示上下文中显示数字,而该显示上下文必须截断数字以适合。您在 Visual Studio 中的什么位置查看这个数字?
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?