note 103028 rejected from language.operators.comparison by thiago
| From: | thiago@php.net | Date: | Mon, 21 Mar 2011 17:14:16 +0000 |
| Subject: | note 103028 rejected from language.operators.comparison by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178056@lists.php.net to get a copy of this message | ||
Note Submitter: vitaliy dot andrianov at gmail dot com
----
Just found a weird thing with float numbers:
var_dump ( (7.12 * 100) == 712 ); // true (as expected)
var_dump ( (8.12 * 100) == 812 ); // false
var_dump ( (int)(8.12 * 100) == 812 ); // false
var_dump ( (8.12 * 100) == (int)812 ); // false
var_dump ( (int)(8.12 * 100) == (int)812 ); // false
The solution is:
var_dump ( round(8.12 * 100) == 812 ); // true
or an optional one just for test:
var_dump ( md5(8.12 * 100) == md5(812) ); // true
I didn't find any explanation of this. I have also checked a range of 0.00 - 100.00 increasing
by 0.01 and there are lots of "false" conditions in different numbers without any logic.
PHP version is 5.2.16; 5.2.17; 5.3.4;
Hope that helps someone.