I have seen this behavior when I try adding double values where one of the value is a negative double, the order in which I add these values apparently does matter. Here's my test
double val1 = -0.06, val2 = 0.04, val3 = 0.02;
double resOrder1 = val1 + val2 + val3;
double resOrder2 = val2 + val3 + val1;
Console.WriteLine(resOrder1); //3.46944695195361E-18
Console.WriteLine(resOrder2); //0
Am I missing some key principle here? Moreover, how do I make sure I get true for if(resOrder1 == 0){}
regardless the addition order. And no I don't want to change the data type to decimal.