note 106131 added to language.operators.comparison
| From: | j-a-n at gmx dot de | Date: | Thu, 13 Oct 2011 09:32:44 +0000 |
| Subject: | note 106131 added to language.operators.comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183843@lists.php.net to get a copy of this message | ||
Please be careful when comparing strings with floats, especally when you are using the , as decimal.
<?php
var_dump($alt);
var_dump($neu);
var_dump($alt == $neu);
?>
string(9) "590217,73"
float(590217,73)
bool(false)
not the float is cast to a string and then string-compared, but the string is cast to a float and
then float-compared.
to compare as strings use strval!
<?php
var_dump(strval($alt));
var_dump(strval($neu));
var_dump(strval($alt) == strval($neu));
?>
string(9) "590217,73"
string(9) "590217,73"
bool(true)
----
Server IP: 217.160.235.204
Probable Submitter: 78.50.226.216
----
Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php
Edit -- https://master.php.net/note/edit/106131
Del: integrated -- https://master.php.net/note/delete/106131/integrated
Del: useless -- https://master.php.net/note/delete/106131/useless
Del: bad code -- https://master.php.net/note/delete/106131/bad+code
Del: spam -- https://master.php.net/note/delete/106131/spam
Del: non-english -- https://master.php.net/note/delete/106131/non-english
Del: in docs -- https://master.php.net/note/delete/106131/in+docs
Del: other reasons-- https://master.php.net/note/delete/106131
Reject -- https://master.php.net/note/reject/106131
Search -- https://master.php.net/manage/user-notes.php