简体   繁体   中英

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:

?r

And the results display the double's value:

0.000056262413896897934

However if I bring up the project in Visual Studio 2017 and type this in the immediate window:

?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:

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. As double is a built in type you can't just change its implementation. For cases like this the debugger has a feature where it will load in DebuggerDisplay implementations externally that are implemented in 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.
  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 .
  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
  4. Build the file with csc /t:library autoexp.cs
  5. Reload VS and run your scenario

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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