title: PHP BCMath cannot handle the exponential number if it is passed to its function, PHP BCMath return " bcmath function argument is not well-formed"
body: <p>I working on the few of the small decimals like 0.0000687, 0.0000063241, 0.0000454. I used BCMath as to get the most precise result because it involved with money calculation, so far BCMath it is very helpfull to me in fixing my previous bug that I faced. But I found that BCMath cannot work well if the exponential value that automatically converted by PHP is being passed to BCMath. Below is the sample code :</p>
  <pre><code> $x = 0.00002123; // let say I got this value from the other computation;
                    // this $x value will automatically turn to exponential 
                    //  value by php because it have few of leading 0 after the '.' 
   
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Ob1MC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ob1MC.png" alt="enter image description here" /></a></p>
  <p>The pattern where the PHP start to convert its real number into exponential number is : (see image below)</p>
  <p><a href="https://i.stack.imgur.com/Ve7C1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ve7C1.png" alt="enter image description here" /></a></p>
  <p>As you can see from the image above, the pattern of PHP start to convert real number to exponential number is when the leading 0 number is 4 times -&gt; 0.0000xxxxx (pattern where PHP start to convert to exponential).</p>
  <p>Then, let say this variable $x will be calculate into one of PHP BCMath function :</p>
  <pre><code># First, I work with float number 
  
  $calculation1 = bcadd($x,5,12); // adding variable $x to 5 
  $calculation2 = bcmul($x,4,12); // multiply variable $x to 4
  $calculation3 = bcdiv($x,5,12); // divide variable $x to 5
   
  # Second, I tried to work with string number
  
  $y = (string) $x;
  $calculation4 = bcadd($y,5,12);
  $calculation5 = bcmul($y,4,12);
  $calculation6 = bcmul($y,4,12);
  </code></pre>
  <p>The result turn out to be error, here the screenshot for variable $x :</p>
  <p><a href="https://i.stack.imgur.com/FLdpQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FLdpQ.png" alt="enter image description here" /></a></p>
  <p>And here the result turn out to be error, here the screenshot for variable $y (pass to string first because BCMath works well working with string):</p>
  <p><a href="https://i.stack.imgur.com/XI0Bl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XI0Bl.png" alt="enter image description here" /></a></p>
  <p><em><strong>Important Note</strong></em> :</p>
  <ul>
  <li>So it turn out BCMath have problem when working with exponential value, I cannot avoid this exponential value because PHP will automatically parse it to exponential number when it reach its pattern (can see image I attach above).</li>
  <li>Considering where variable $x I get from different calculation, so in the real code, I cannot really hardcoded it to the way I want.</li>
  </ul>