The thing people forget is that a float is only an approximation to a number, it is rarely the exact number you want it to be because it is a binary fraction. Just like decimal numbers you can have recurring numbers. For example you can not write down an exact decimal value for one third, there are many decimal values you can't express as a binary fraction or floating point number.
The best way to compair floats fro equality is to subtract the number you want to test from the value you want to compair it with. Take the absoloute value of the result and test if that is greater than a small number.
If you read the page I linked to, Grumpy_Mike, your solution is not the best idea. It is better to scale the "small" number to the relative size of the values being compared.
Grumpy_Mike:
The best way to compair floats fro equality is to subtract the number you want to take from the value you want to compair it with. Take the absoloute value of the result and test if that is greater than a small number.
Hi!!
First of you, thank you and everybody that answered my question!!
Just a question..
What exactly you meant by "The best way to compair floats fro equality is to subtract the number you want to take from the value you want to compair it with."
KeithRB:
Read the page I linked to and all will be explained. You compare your number to 2.0.
Read it but it is a bit biased against the method I use because it assumes that you use it blindly without thinking about what you are doing. What the "approve" method does is do about half of that thinking for you.