note 46721 added to language.operators.comparison
| From: | darkcryst at gmail dot com | Date: | Thu, 21 Oct 2004 10:35:54 +0000 |
| Subject: | note 46721 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78874@lists.php.net to get a copy of this message | ||
be REALLY careful when comparing float values. PHP, like most languages, is vunerable to he problems
of floating point precision.
Do NOT compare floats directly, and this also means any decimal value at all.
The headaches finding out if $var = 0.3 caused me are unbelievable. even though the stored variable
WAS 0.3 it was still ignoring it - this was to do with the internal float not recognising it as 0.3
even though it *displayed* it as 0.3 when echo'd or printed... basically it was stored
imprecisly, but not able to display it as such.
I ended up having to compare after multiplying by 10, rounding, and then dividing by 10...
rediculous, but sadly the only way I could find to reliably do it. The round seemed to remove the
break in the float...
jesus that took me ages to find...
----
Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46721
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46721&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46721&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46721&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46721&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46721&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46721&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46721&report=yes
Search -- http://master.php.net/manage/user-notes.php