$price = "19.65";
echo intval($price * 100); // 1964
echo $price * 100; // 1965
I try to format the price amount, but I found the above solution have different result, any idea why?
$price = "19.65";
echo intval($price * 100); // 1964
echo $price * 100; // 1965
I try to format the price amount, but I found the above solution have different result, any idea why?
Seems to be a floating point issue. This is from php.net manual page,
see http://php.net/manual/en/function.intval.php#101439
see http://php.net/manual/en/function.intval.php#112039
Do not use intval() when you really want round(). This is due to how PHP handles precision.
$n="19.99";
print intval($n*100); // prints 1998
print intval(strval($n*100)); // prints 1999