|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-03-26 12:08 UTC] james dot turner dot phpninja at gmail dot com
Description: ------------ bcadd does not appear to work for certain numbers when using floats as inputs rather than strings. This is particularly apparent if you json_decode from json to php variables where floats are generated as you get floats not strings. Any attempt at casting to a string produces the same output. I can only assume it's actually an issue with float->string casting. Test script: --------------- $a = -0.05648055; $b = -0.00000545; $c = bcadd($a,$b,9); $d = $a+$b; echo $c; // => -0.05648055 <- WRONG echo $d; // => -0.056486 <- CORRECT assert($c == -0.056486); Expected result: ---------------- assert ok Usage of string literals for the negative floats works fine. However casting the floats to strings fails (which is why I assume that bcadd also has the same problem in casting to strings before computation). Actual result: -------------- assert fail PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 02 11:00:01 2025 UTC |
Actually the bcmath extension doesn't like scientific notation. var_dump((string)-0.00000545); string(8) "-5.45E-6" and var_dump(bcadd("-0.05648055","-5.45E-6",9)); string(12) "-0.056480550" ------------ Would be great if someone could make bcmath support scientific notation...