From: hpdl at oscommerce dot com Operating system: Linux PHP version: 4.3.1 PHP Bug Type: Math related Bug description: number_format rounding differences for floats and strings
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 bug report at http://bugs.php.net/?id=22712&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=22712&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=22712&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=22712&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=22712&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=22712&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=22712&r=support Expected behavior: http://bugs.php.net/fix.php?id=22712&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=22712&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=22712&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=22712&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=22712&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=22712&r=dst IIS Stability: http://bugs.php.net/fix.php?id=22712&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=22712&r=gnused