Visual Studio expands from 1.1 to 1.1000000000000001

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

target_height = height * 1.1

when I insert it into the MVC3 project, it expands to

target_height = height * 1.1000000000000001

Now, if I type 1.2, this is normal, nothing happens, but if I type 1.12, it expands to 1.1200000000000001.

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

What's happening???

+3
source share
3 answers

, autocomplete "" . http://accessmvp.com/Strive4Peace/VBA/VBA_L1_02_Crystal.pdf, VB ", ". int * double, , int * int ( ), 1.1 1.12 (epsilon = 1.11e-16).

, - , , , VB.NET MVCx, , .

+1

1.1 11/10, round [(2 ^ 53 * 11)/10]/(2 ^ 53), 11/10. 53 , , , , - 1 3/16 " 30,1625 , 1/64 , 30,1625 +/- 0,399675 , , 30,2 +/- 0,4 .

, Visual Studio , 1.1, 1.1000000000000001. , 1.1 . , 1.1, . , , , "". , 1.1 11/10 ( 11), (1.1-1.0) (1/10) ( 10 ).

0

1.1 and 1.12 should not have an exact binary representation.

see this: https://stackoverflow.com/questions/634206/what-every-programmer-should-know-about

-2
source

Source: https://habr.com/ru/post/1795454/


All Articles