#42871 [Opn->Bgs]: bcmath incorrect results / number format

From: Date: Fri, 05 Oct 2007 23:49:36 +0000
Subject: #42871 [Opn->Bgs]: bcmath incorrect results / number format
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-118233@lists.php.net to get a copy of this message
ID: 42871 Updated by: jani@php.net Reported By: rbro at hotmail dot com -Status: Open +Status: Bogus Bug Type: BC math related Operating System: Linux PHP Version: 5CVS-2007-10-05 (snap) New Comment: These functions expect a _string_ to be passed to them. You're not supposed to pass any float/integers, as they're simply cast to string and you get this _expected_ behaviour. Previous Comments: ------------------------------------------------------------------------ [2007-10-05 18:57:08] rbro at hotmail dot com Description: ------------ When adding certain floating point numbers together using bcadd (or using the other bcmath functions), I'm receiving invalid results at times depending on the inputs. It appears that with recent PHP releases, PHP is expressing certain floating point numbers in scientific notation which bcmath is not correctly handling. Using my example below, PHP is expressing the number 1200000.00 as 1.2E+6 which is causing incorrect results from bcadd. Reproduce code: --------------- <?php bcscale(2); echo bcadd(1200000, 1)."\n"; echo bcadd(1200000.00, 1)."\n"; Expected result: ---------------- 1200001.00 1200001.00 Actual result: -------------- 1200001.00 1.00 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42871&edit=1

« previous php.bugs (#118233) next »