|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13551 BC functions apply decimal places argument also on arguments
Submitted: 2001-10-04 19:18 UTC Modified: 2003-02-04 13:05 UTC
From: mlemos at acm dot org Assigned: pollita (profile)
Status: Closed Package: BC math related
PHP Version: 4.0.6 OS: Linux 2.2.18
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mlemos at acm dot org
New email:
PHP Version: OS:


 [2001-10-04 19:18 UTC] mlemos at acm dot org
BC functions apply decimal places also on arguments but it should only apply them on the result.

For example bcmul('8.78','100',0) should return 878 and not 800 as it does now.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-10-04 19:49 UTC]
Confirmed with latest CVS. Either the documentation is wrong or the implementation. Both won't need rocket sience to fix ...

Btw, this seems to be true for all bc*() functions.

Probably the documentation isn't clear enough about the current behaviour. Andi?

- Markus
 [2001-10-05 02:21 UTC]
It's not a bug, but a feature (tm). BC only works with integer values, and all arguments must be integer values.
However, the documentation is not quite clear here.

 [2001-10-05 09:02 UTC]
That is incorrect. BC is for arbitrary percision arithmetic. Arguments should be strings not integers. Just change the precision argument in the example from 0 to 2 and you will see that it will consider the decimal places of the multiplication arguments.

The problem is that the way PHP BC module is working is that it applies the decimal places to arguments when it should only apply to the result.

bcmul('8.78','100',2) should be '878.00'


bcmul('8.78','100',0) should be '878' and not '800', otherwise BC PHP module is useless because you can't perform a calculation and control the decimal places of the result without affecting the operands.

It should work like sprintf("%.2f",$operand_1*$operand_2) where 2 is the number of decimal places of the output and and not of the operand values because these may have much more decimal places than the result.

 [2003-01-02 18:28 UTC]
Andi can you take a look? Or just close it if it's bogus.
 [2003-02-04 13:05 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

bcmath functions now apply scale only to result.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 21 06:01:29 2024 UTC