duluter
02-02-2010, 09:01 AM
Hi, all.
I was reading that a "safe" way to test equality of two double-type variables is to compute the absolute value of their difference and then compare that to some predetermined acceptable error margin. So, if the absolute difference is less than 0.0000001, then they are considered equal (for example).
I was wondering if there is a reason why you couldn't just round the two variables, say to 6 decimals (or whatever number of decimals suits your needs), and then compare them directly:
Double var1 = 10.900000001
Double var2 = 10.900000000
If Round(var1, 6) = Round(var2, 6) Then 'They're equal.
Would this work?
Thanks,
Duluter
I was reading that a "safe" way to test equality of two double-type variables is to compute the absolute value of their difference and then compare that to some predetermined acceptable error margin. So, if the absolute difference is less than 0.0000001, then they are considered equal (for example).
I was wondering if there is a reason why you couldn't just round the two variables, say to 6 decimals (or whatever number of decimals suits your needs), and then compare them directly:
Double var1 = 10.900000001
Double var2 = 10.900000000
If Round(var1, 6) = Round(var2, 6) Then 'They're equal.
Would this work?
Thanks,
Duluter