title: What is the max. amount of decimals I should display for a float? (PHP)
body: <p>I still can't get accurate results. What is the max. amount of decimals I should display if I want it to be as accurate as possible?</p>
  
  <p>Some code (ready to be copy-pasted and tested):</p>
  
  <pre><code>// Test with 5 decimals 
  $a = 0.00001;
  echo bcadd($a,$a,5) . '&lt;br/&gt;';
  echo bcadd($a,$a,6) . '&lt;br/&gt;';
  echo number_format(bcadd($a,$a,5),5) . '&lt;br/&gt;';
  echo number_format(bcadd($a,$a,5),6) . '&lt;br/&gt;';
  echo bcadd(0.00001,0.00001,20) . '&lt;br/&gt;';
  echo number_format(bcadd($a,$a,20),5) . '&lt;br/&gt;';
  echo number_format(bcadd($a,$a,20),21) . '&lt;br/&gt;&lt;br/&gt;';
  
  /* Output:
  0.00000
  0.000000
  0.00000
  0.000000
  0.00000000000000000000
  0.00000
  0.000000000000000000000
  */
  
  // Test with 4 decimals
  $a = 0.0001;
  echo bcadd($a,$a,5) . '&lt;br/&gt;';
  echo bcadd($a,$a,6) . '&lt;br/&gt;';
  echo number_format(bcadd($a,$a,5),5) . '&lt;br/&gt;';
  echo number_format(bcadd($a,$a,5),6) . '&lt;br/&gt;';
  echo bcadd(0.00001,0.00001,20) . '&lt;br/&gt;'; // wtf? this outputs 0 too?
  echo number_format(bcadd($a,$a,20),5) . '&lt;br/&gt;';
  echo number_format(bcadd($a,$a,20),21) . '&lt;br/&gt;';
  
  /* Output:
  0.00020
  0.000200
  0.00020
  0.000200
  0.00000000000000000000
  0.00020
  0.000200000000000000010
  */
  </code></pre>
  
  <p>Should I infer that the answer is 4 ??? But I still have a problem in the line with a comment</p>
  
  <p>Edit: I don't think anyone understood my tests. I know floats are inaccurate. But one thing is 1 != 0.98990123, and other thing is 1 != 0.0000. If I set 4 as the precision in the bc* function, I expect to get at least 0.9899 (if the perfect answer were 1), not 0.0000. One thing is 'not perfectly accurate for infinite precision', other thing is 'completely useless'.</p>
  
  <p>Edit 2: @Michael Borgwardt has the solution</p>