ID: 22712
Updated by: [EMAIL PROTECTED]
Reported By: hpdl at oscommerce dot com
-Status: Open
+Status: Bogus
Bug Type: Math related
Operating System: Linux
PHP Version: 4.3.1
New Comment:
It's a float/maths problem, nothing to do with PHP specific.
Derick
Previous Comments:
------------------------------------------------------------------------
[2003-03-14 14:32:09] hpdl at oscommerce dot com
We at osCommerce are witnessing rounding problems in our
taxes logic and have made a reproduceable script below.
number_format() produces different rounding results when
floats or strings are passed to the function.
<?php
$price = '100.0000';
// Canada GST 7%
$price = '1.07' * $price;
// Canada/Quebec PST 7.5%
$price = '1.075' * $price;
echo '$price: ' . $price . '<br>' . "\n" .
'number_format($price, 2): ' .
number_format($price, 2) . '<br>' . "\n" .
'number_format((string)$price, 2): ' .
number_format((string)$price, 2);
?>
The correct results are produced when the string value is
passed. The float value produces incorrect results.
I do not know if this is a problem with the number_format
function, or if it is due to floats/mathematics.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=22712&edit=1