php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66364 BCMath bcmul ignores scale parameter
Submitted: 2013-12-28 03:39 UTC Modified: 2017-09-18 13:23 UTC
Votes:4
Avg. Score:4.0 ± 1.0
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:0 (0.0%)
From: self at jacobbudin dot com Assigned: cmb (profile)
Status: Closed Package: BC math related
PHP Version: 5.5.7 OS: Fedora 20
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
23 - 4 = ?
Subscribe to this entry?

 
 [2013-12-28 03:39 UTC] self at jacobbudin dot com
Description:
------------
BCMath's bcmul function ignores the scale parameter. When the result's scale has fewer the digits than the requested scale, the trailing zeros are not appended to the returned string as is the case with bcadd, bcsub, and bcdiv.

Test script:
---------------
<?php echo bcmul("0.3", "0.2", 4);

Expected result:
----------------
0.0600

Actual result:
--------------
0.06

Patches

bcmul-scale (last revision 2013-12-28 03:40 UTC by self at jacobbudin dot com)

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-07-27 05:16 UTC] pollita@php.net
-Status: Open +Status: Analyzed
 [2016-07-27 05:16 UTC] pollita@php.net
bcmul() *sort-of* ignores scale.  What it does is treat the scale param as a "maximum scale".  In the case of your example, the answer only has two significant decimal places, so the scale parameter of 4 is truncated to 2.

That said, this seems to disagree with most other bcmath functions, so I'm less likely to call it a documentation problem and consider it a real bug.
 [2016-12-06 17:29 UTC] powtac at gmx dot de
The problem also exists on PHP 5.6.25 Ubuntu.
 [2017-09-18 13:21 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=870ed5106d6274905b5aa4341429deef12c92e55
Log: Fixed bug #66364 (BCMath bcmul ignores scale parameter)
 [2017-09-18 13:21 UTC] cmb@php.net
-Status: Analyzed +Status: Closed
 [2017-09-18 13:23 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2017-09-18 13:23 UTC] cmb@php.net
This issue will be fixed as of PHP 7.3.0 only, to mitigate the BC
break.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 09:01:29 2024 UTC