How can I compare doubles?
-
hello can you tell me how can I compare two double vars in my app i tried: if (var.Equals(.4)) but it's not working... and i am sure the two var contains the same value (i used MessageBox to print the vals) please help me
Hello the Equals() method is usually used to compare two reference types -Yet it still can compare value types-. Instead you should take a shorter approach in comparing two value types by using the == operator
double A = 5.4;
double B = 2.3;if (A == B)
{
//Do something
}
else if(A == 2.7)
{
//Do somthing
}Regards:rose:
-
hello can you tell me how can I compare two double vars in my app i tried: if (var.Equals(.4)) but it's not working... and i am sure the two var contains the same value (i used MessageBox to print the vals) please help me
hy, have you tried to compare something like: double a; double b; if (a <= b) { } if (a >= b) { } it works just fine with double as with integers. Do your best to be the best
-
hello can you tell me how can I compare two double vars in my app i tried: if (var.Equals(.4)) but it's not working... and i am sure the two var contains the same value (i used MessageBox to print the vals) please help me
-
hello can you tell me how can I compare two double vars in my app i tried: if (var.Equals(.4)) but it's not working... and i am sure the two var contains the same value (i used MessageBox to print the vals) please help me
You better use decimal instead of double in such circumstances.