Possible Duplicates:
C# float bug? 0.1 - 0.1 = 1.490116E-08
problem in comparing double values in C#
In my application I want to test if float a=float b, and then do some operations. But, I wonder, that in float type 0.2+0.3==0.5 is returning false .
So here is some part of my code
float a = 0.3f;
float b = 0.2f;
float c = 0.5f;
if (a + b == c)
Console.WriteLine("true");
else
Console.WriteLine("false");
Console.WriteLine(a+b);
Console.WriteLine(c);
And here is result of this part
false
0.5
0.5
I can't figure out what is wrong here... I can use double or decimal instead float, but I want to know what's wrong here. Thanks for help.