Posted by Fabian Hore on 02/28/06 14:26
comparing floating points is (I have read) unreliable unlike integers and
best avoided.
when comparing monitary values I suggest converting to a common string
format and then comparing exactly.
- or - scaling up to a nice solid integer so (float)24.95 is compared as
(int)2495 or something like that.
cheers,
--
<http://plug.whiteinteractive.com/>
"Smiley" <none@ofyourbusiness.com> wrote in message
news:w9GdnZoFeKXbPJ7ZnZ2dnUVZ_tmdnZ2d@golden.net...
> In part of my script, I'm testing 2 variables - $price and $amount - to
> make sure they're the same. If they're not the same an error message
> should come up.
>
> But the error message comes up even when they are the same. I've added a
> small test to make sure of it:
>
> if($price != $amount)
> {
> echo "|$price|$amount|";
> }
>
> I go the following result:
> |24.95|24.95|As you can see, there is no extraneous invisible character in
> either variable. Both are exactly the same. So why did they evaluate as
> not equal to one another??
>
>
Navigation:
[Reply to this message]
|