note 103028 added to language.operators.comparison

From: Date: Mon, 21 Mar 2011 15:38:37 +0000
Subject: note 103028 added to language.operators.comparison
Groups: php.notes 
Request: Send a blank email to php-notes+get-178053@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.197 Probable Submitter: 91.188.61.67 ---- Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php Edit -- https://master.php.net/note/edit/103028 Del: integrated -- https://master.php.net/note/delete/103028/integrated Del: useless -- https://master.php.net/note/delete/103028/useless Del: bad code -- https://master.php.net/note/delete/103028/bad+code Del: spam -- https://master.php.net/note/delete/103028/spam Del: non-english -- https://master.php.net/note/delete/103028/non-english Del: in docs -- https://master.php.net/note/delete/103028/in+docs Del: other reasons-- https://master.php.net/note/delete/103028 Reject -- https://master.php.net/note/reject/103028 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178053) next »