Completely bizarre PHP behavior.
Posted
by George Edison
on Stack Overflow
See other posts from Stack Overflow
or by George Edison
Published on 2010-03-23T03:34:11Z
Indexed on
2010/03/23
3:41 UTC
Read the original article
Hit count: 385
Boy, this one is really weird. I expect the following code to print 1990, but it prints 1989!
$val = '$19.9';
$val = preg_replace('/[^\d.]/','',$val);
$val = intval($val * 100);
echo $val;
Why on earth is this happening?
Edit: and this code:
$val = '$19.9';
$val = preg_replace('/[^\d.]/','',$val);
echo $val . "<br>";
$val = $val * 100;
echo $val . "<br>";
$val = intval($val);
echo $val;
Prints:
19.9
1990
1989
Why does intval(1990)
equal 1989
???
© Stack Overflow or respective owner