Strange behaviour with float values
| From: | Daniel Reichenbach | Date: | Wed, 06 Mar 2002 12:52:18 +0000 |
| Subject: | Strange behaviour with float values | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-87451@lists.php.net to get a copy of this message | ||
Hy list,
just stumbled accross a strange behaviour with float values in php.
Take a look at the attached snippet. If I do a var_dump of $x and $y
both show as float(3.3) but are not similar. Why is this happening?
If i remember math classes right 10*0.33 should be 3.3?
Greetings,
Daniel
<?php
$x = 10 * 0.33;
$y = 3.3;
echo $x."<br>\n";
echo $y."<br>\n";
if ($x == $y)
{ echo "x = y"; }
$x = round($x,2);
if ($x == $y)
{ echo "x = y (round)"; }
?>
--
Daniel Reichenbach
Software Entwicklung
Pixum AG
Gottesweg 64
D-50969 Köln
Germany
Fon: +49 221 6500 40 40
Fax: +49 221 6500 40 99