note 47273 added to language.types.float
| From: | onlineMarcus at hotmail dot com | Date: | Tue, 09 Nov 2004 21:04:23 +0000 |
| Subject: | note 47273 added to language.types.float | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80318@lists.php.net to get a copy of this message | ||
Floating point numbers can't accurately be compared, as noted below (I suppose because of
hidden precision). The programers of this manual should note this to keep php programmers from
wasting development time! I had to cast the values to a string and then compare them:
if ((string)$ordersSubtotal != (string)$subtotal){
etc.
}
I searched for this as a bug and found that it was reported. But, the report was tagged as
"Bogus". It may not technically be a bug, but funtionally it is! Comparisons in all other
types work! If the designers know this is an exception, then they should created a function just
for floating point comparision and note it in the relative operator and type sections of this
manual.
----
Manual Page -- http://www.php.net/manual/en/language.types.float.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47273
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47273&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47273&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47273&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47273&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47273&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47273&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47273&report=yes
Search -- http://master.php.net/manage/user-notes.php