Using bcdiv, i can't divide with small float using scientific notation :
Working code :
bcscale(30);
$a = '1' ;
$b = '0.00000001';
$result = bcdiv($a, $b);
var_dump($result);
Results in :
string(20) "100000000.0000000000"
Non-working code :
bcscale(30);
$a = '1' ;
$b = '1e-8';
$result = bcdiv($a, $b);
var_dump($result);
Results in :
Warning: bcdiv() [function.bcdiv]: Division by zero in C:\wamp\www\utilitaires\test_bcdiv.php on line XX NULL
How can i do this division properly, with the less precision loss ?
That is because, actually,
bcmath
doesn't support scientific notation. It isn't mentioned in manuals, but as you can see, in it's implementation argument conversion is used, it's namedphp_str2num
:and so
bc_str2num
:-not hard to see that it will fail on scientific notation (well-commented). Perhaps documentation needs to be updated (to mention that implicitly).
Possible solution will be to convert your string to plain view before applying
bcmath
functions