Can I control the number of digits displayed in debugger windows for float and double variables?

后端 未结 6 1912
别跟我提以往
别跟我提以往 2021-01-08 00:51

In Visual Studio 2012, I\'m looking for a way to customize the default display of floating point types in the Autos, Locals, and Watch windows. I\'m familiar with the Native

6条回答
  •  一生所求
    2021-01-08 01:32

    You don't have much control over this. We were able to get something a little bit better than the default view, however, by casting our doubles to floats for the preview:

    {{x={(float)x} y={(float)y}}}

    We left them as doubles in the unfolded version so that you can see the true values. This was enough for us to pack four or five values horizontally, instead of the usual three. This still has some disadvantages: The last couple of digits on the float will be garbage, and might make you think you have precision errors when in fact you don't. However, until Microsoft gets around to adding proper formatting specifiers for numeric output, this is perhaps the best we can do.

    Incidentally, you can probably get a similar "chopped precision" by casting your floats to ints, if the values are typically large enough.

提交回复
热议问题