Strange variable compariso result

From: Date: Fri, 18 Oct 2002 16:27:06 +0000
Subject: Strange variable compariso result
Groups: php.general 
Request: Send a blank email to php-general+get-120513@lists.php.net to get a copy of this message
Hi to all. I have a very strange result from this code: I have a query that get a "select sum(columnname) as checksum from table" and a $total variable passed by a Form in post method . I manage both variables as string. After i make $tot=mysql_fetch_object($query_check_ordine); if(($tot->checksum-$total)!=0) { echo " There is a problem"; exit; } else { echo "OK"; } After this i tried to print the 2 values and both are, for example, 9.3 . But if i sottract the 2 variables i obtain 3.5527136766005E-15 instead of 0 . I think that PHP automatically try to evaluate the strings as floats (this is i want too). I tried to compare with != the two variables to see if them are equals and PHP say that the are not equal, but if i print them, them are equals. I tried to settype to floats directly the variables and the result is the same. After all if i settype to string directly the variables the comparison occur correctly. Have you any idea of this behaviour?? Thanks in advice, Bye Marcello

« previous php.general (#120513) next »