note 106131 deleted from language.operators.comparison by crell
| From: | crell@php.net | Date: | Thu, 31 Mar 2022 17:47:05 +0000 |
| Subject: | note 106131 deleted from language.operators.comparison by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217877@lists.php.net to get a copy of this message | ||
Note Submitter: j-a-n at gmx dot de
----
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)