When comparing floating point numbers, make sure you round to an acceptable level of rounding for the type of application you are using.
Languages Focus: Comparison Operators
A comparison operator compares two values either literals as in "Hello" and 3 or variables as in X and Counter. Most languages use the same operators for comparing both numbers and strings. Perl, for example, uses separate sets of comparison operators for numbers and strings.
PHP Comparison Operators
Common comparison operators:
== |
equal |
!= or <> |
not equal |
< |
less than |
> |
greater than |
<= |
less than or equal |
>= |
greater than or equal |
PHP 4 and above also offers === for indentical (equal plus same type) and !== for not identical (not equal or not same type).
Syntax Example: //Does PHP evaluate the math correctly? No!
if (.1 + .1 + .1 == .3) {
echo "correct";
}
else {
echo "not correct";
}