php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42871 bcmath incorrect results / number format
Submitted: 2007-10-05 18:57 UTC Modified: 2007-10-05 23:49 UTC
From: rbro at hotmail dot com Assigned:
Status: Not a bug Package: BC math related
PHP Version: 5CVS-2007-10-05 (snap) OS: Linux
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rbro at hotmail dot com
New email:
PHP Version: OS:

 

 [2007-10-05 18:57 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-05 23:49 UTC] jani@php.net
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.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 18 05:03:36 2021 UTC