|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-03-16 16:00 UTC] sunofman at sympatico dot ca
$x = 0.0;
$y = 0.7;
do {
if ($x == $y) {
PRINT "found<br>";
} else {
PRINT "not found<br>";
}
$x += 0.1;
} while($x <= 1.0);
When $y is 0.0 to 0.7 everything works fine and it will find the match...if you make $y = 0.8 or higher it will fail to find the match.
I'm using the basic install of 4.3.1 (it happens in older versions as well)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 12:00:02 2025 UTC |
<?php ini_set("precision",18); $x = 0.0; $y = 0.8; do { if ($x == $y) { PRINT "found\n"; } else { PRINT "not found\n"; } $x += 0.1; echo $x; } while($x <= 1.0); ?> Try this and you'll see why.. And then read this to know why that happens: http://www.php.net/manual/en/language.types.float.php