|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-06-23 11:15 UTC] blazexerit at yahoo dot co dot jp
Description:
------------
after Test script
php > var_dump($now,$next);
int(1060)
double(1060)
php > if($now == $next) echo 1,PHP_EOL; else echo 0,PHP_EOL;
0
but,
php > if((int)1060 == (double)1060) echo 1,PHP_EOL; else echo 0,PHP_EOL;
1
Test script:
---------------
$r = 1060;
$now = 0; $next = 0;
$per = $r/50;
$i=0;
while($i!=$r){
$now++;
while($now >= $next){
$next += $per;
}
$i++;
}
var_dump($now,$next);
if($now == $next) echo 1,PHP_EOL; else echo 0,PHP_EOL;
Expected result:
----------------
$now is 1060.
$next is 1060.
So, "if($now==$next)" will return true.
Actual result:
--------------
"if($now==$next)" returns false.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2026 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 07 04:00:01 2026 UTC |
That's controlled by your "precision" php.ini setting. php > var_dump(1060 + 1/50); float(1060.02) php > ini_set("precision", 20); php > var_dump(1060 + 1/50); float(1060.0199999999999818)