简体   繁体   English

vs2013 / vs2017在即时窗口中显示双精度不同

[英]Display double in immediate window different in vs2013/vs2017

I have the following line of code: 我有以下代码行:

double r = 0.000056262413896897934;

In visual studio 2013, I go to the immediate windows and type: 在Visual Studio 2013中,我转到即时窗口并键入:

?r

And the results display the double's value: 结果显示了double的值:

0.000056262413896897934

However if I bring up the project in Visual Studio 2017 and type this in the immediate window: 但是,如果我在Visual Studio 2017中调出项目并在立即窗口中键入以下内容:

?r

It display the following result (exponential format): 它显示以下结果(指数格式):

5.6262413896897934E-05

I would like Visual Studio 2017 to display the format in the same way as Visual Studio 2013 does: 我希望Visual Studio 2017以与Visual Studio 2013相同的方式显示格式:

0.000056262413896897934

Not just for this variable or this solution but as a permanent setting. 不仅针对此变量或此解决方案,还作为永久设置。 Does anyone know how to do this? 有谁知道如何做到这一点? Thanks in advance 提前致谢

As @Amy mentioned you can use DebuggerDisplay to change the appearance of an object in the debugger. 正如@Amy提到的,您可以使用DebuggerDisplay来更改调试器中对象的外观。 As double is a built in type you can't just change its implementation. 由于double是内置类型,您不能仅更改其实现。 For cases like this the debugger has a feature where it will load in DebuggerDisplay implementations externally that are implemented in autoexp.cs 对于这种情况,调试器具有一项功能,可以在autoexp.cs实现的外部DebuggerDisplay实现中autoexp.cs

  1. Open (as admin) the autoexep.cs file which should be in a directory that looks like: C:\\Program Files (x86)\\Microsoft Visual Studio\\16\\Preview\\Common7\\Packages\\Debugger\\Visualizers\\Original obviously that will change with your VS version but if you search for autoexp.cs you'll find it. 打开(以管理员身份) autoexep.cs文件,该文件应该位于以下目录中: C:\\Program Files (x86)\\Microsoft Visual Studio\\16\\Preview\\Common7\\Packages\\Debugger\\Visualizers\\Original显然该更改VS版本,但如果搜索autoexp.cs ,则会找到它。
  2. In that file, add the code below: [assembly: DebuggerDisplay(@"{ToString(""F17""),nq}", Target = typeof(Double))] that's going to tell the debugger to basically execute ToString("F17") whenever it's displaying a double . 在该文件中,添加以下代码: [assembly: DebuggerDisplay(@"{ToString(""F17""),nq}", Target = typeof(Double))] ,这将告诉调试器基本上执行ToString("F17")只要它显示double
  3. Open a Developer Command Prompt as admin and navigate to where autoexp.cs is eg C:\\Program Files (x86)\\Microsoft Visual Studio\\16\\Preview\\Common7\\Packages\\Debugger\\Visualizers\\Original 以管理员身份打开开发人员命令提示符,并导航到autoexp.cs所在的autoexp.cs ,例如C:\\Program Files (x86)\\Microsoft Visual Studio\\16\\Preview\\Common7\\Packages\\Debugger\\Visualizers\\Original
  4. Build the file with csc /t:library autoexp.cs 使用csc /t:library autoexp.cs构建文件
  5. Reload VS and run your scenario 重新加载VS并运行您的方案

You should then see something like: 你应该看到类似的东西:

立即窗口评估两倍

More info on DebuggerDisplay is in our docs over at: https://docs.microsoft.com/en-us/visualstudio/debugger/using-the-debuggerdisplay-attribute?view=vs-2017 and more info on the ToString implementation for Double is over at: https://docs.microsoft.com/en-us/dotnet/api/system.double.tostring?view=netframework-4.7.2 . 有关DebuggerDisplay更多信息,请访问我们的文档, 网址为: https : //docs.microsoft.com/zh-cn/visualstudio/debugger/using-the-debuggerdisplay-attribute? ToString以及有关ToString实现的更多信息Double结束于: https : //docs.microsoft.com/zh-cn/dotnet/api/system.double.tostring?view=netframework-4.7.2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM