L
Lothar Behrens
Hi,
I have found a problem in my unit tests that my code does not
calculate exact values.
My code produced 2.8000000000000003 but not 2.7000000000000003. In
both cases
I expected 2.8 / 2.7.
And when I change the calculation I get exact values. Why does this
happen?
I am using Visual Studio 2008 Professional 9.0.30729.1 SP and .NET 3.5
SP1.
Here is a sample from my watch window:
28.000000 * (100.000000 / 100.0000000) / (100.0000000 / 10.0000000)
2.8 double
28.000000 * (100.000000 / 100.0000000) * (10.0000000 / 100.0000000)
2.8000000000000003 double
27.000000 * (100.000000 / 100.0000000) * (10.0000000 / 100.0000000)
2.7 double
Thanks
Lothar
I have found a problem in my unit tests that my code does not
calculate exact values.
My code produced 2.8000000000000003 but not 2.7000000000000003. In
both cases
I expected 2.8 / 2.7.
And when I change the calculation I get exact values. Why does this
happen?
I am using Visual Studio 2008 Professional 9.0.30729.1 SP and .NET 3.5
SP1.
Here is a sample from my watch window:
28.000000 * (100.000000 / 100.0000000) / (100.0000000 / 10.0000000)
2.8 double
28.000000 * (100.000000 / 100.0000000) * (10.0000000 / 100.0000000)
2.8000000000000003 double
27.000000 * (100.000000 / 100.0000000) * (10.0000000 / 100.0000000)
2.7 double
Thanks
Lothar