本文介绍了Visual Studio将1.1扩展到1.100000000000000001的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

至少对我来说,这是最有趣的Visual Studio 2010行为。我正在开发MVC3项目,我从另外一个项目中复制了一行代码(VS2010也是MVC1),看起来像这样:

  target_height = height * 1.1 

当我将它粘贴到MVC3项目中时,到

  target_height = height * 1.1000000000000001 



现在,如果我输入1.2,没关系,没有任何反应,但是如果输入1.12,它会扩展到1.1200000000000001。


$ b target_height高度是整数。为什么一个Visual Studio显示1.1而其他扩展到1.1000000000000001?



发生了什么???

解决方案

我认为这是自动完成疯了,并开始修正浮动点常量到允许值。正如中所写, VB自动完成实际上只是试图提供专门适用于这种数据类型的东西。 int * double可以理解为不会被截断为int * int(自动转换总是只发生在需要的时候),你看到的是1.1或1.12(epsilon = 1.11e-16)的双重表示。

我认为在发生这种情况时,仍然需要进一步的检查或验证来学习确切的条件,但是因为我没有使用VB.NET或MVCx,所以我不愿意这么做。 em>


This is, at least for me, most bizzare Visual Studio 2010 behaviour ever. I'm working on MVC3 project, I copied a line of code from another project (VS2010 also, MVC1 if it matters) which looks like this:

target_height = height * 1.1

when I paste it into MVC3 project, it gets expanded to

target_height = height * 1.1000000000000001

Now, if I type 1.2, it's fine, nothing happens, but if I type 1.12 it is expanded to 1.1200000000000001.

Both target_height and height are integers. Why does one Visual Studio display 1.1 while other expands it to 1.1000000000000001?

What is going on???

解决方案

I think it is autocomplete went crazy and started fixing floating points constant into "allowed" values. As written in http://accessmvp.com/Strive4Peace/VBA/VBA_L1_02_Crystal.pdf , VB autocomplete really tries to offer only "things that apply specifically to that data type". int * double is understandably not truncated into int * int (automatic conversions always happen only as needed) and what you see is double representation of 1.1 or 1.12 (epsilon = 1.11e-16).

I think it would still need some further checking or verification to learn exact conditions when this happens, but as I am not using VB.NET or MVCx this is not something I am willing to do.

这篇关于Visual Studio将1.1扩展到1.100000000000000001的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 08:07