Double 常量在 VS 中显示时是否会被截断?

发布于 2024-09-24 11:01:27 字数 126 浏览 1 评论 0原文

根据 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

祁梦 2024-10-01 11:01:27

我不知道为什么 OP 没有发布这个,因为它会让事情变得非常清楚,但你可以按如下方式重现:

  • 打开 IDE
  • 将 Math.PI 输入到 .cs 文件中。
  • 右键单击 Math.PI,然后单击“转到定义”,

这将打开 Math 的元数据文件,其中包含以下内容:

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

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;
时间海 2024-10-01 11:01:27

很抱歉重复一遍,但是您如何获得该号码?如果我将鼠标悬停在常量上或在 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.

温折酒 2024-10-01 11:01:27

你可以责怪 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...

瞳孔里扚悲伤 2024-10-01 11:01:27

也许您有一个 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文