title: Convert float to plain string representation
body: <p>SO,</p>
  
  <p><strong>The problem</strong></p>
  
  <p>My question is about trivial thing: how to convert numeric string to it's plain ("native") representation. That means: if numeric string is already in plain view, leave it as it is, but if it is in scientific notation, convert it. Sample:</p>
  
  <pre>
  "3"          -->  "3"
  "1.5"        -->  "1.5"
  "-15.482E-2" -->  "-0.15482"
  </pre>
  
  <p>Numeric string supposed to be valid, and if it's not - then it's not a case for conversion (we're free to return null or empty string, for example).</p>
  
  <p><em>Use-case</em></p>
  
  <p>That is needed for <code>bcmath</code> because it can't work with scientific floats. Thus, they need to be converted to plain strings (asked <a href="https://stackoverflow.com/questions/21886257/bcdiv-using-very-small-float-with-scientific-notation-cause-division-by-zero-e">here</a>). So important consequence from this use-case is that numeric string can be something like <code>1E-300</code> or <code>1E+500</code>. Since we're working with <code>bcmath</code> - it's intention is to handle such things.</p>
  
  <p><strong>My approach</strong></p>
  
  <p>For now, I've implemented that with <a href="/questions/tagged/regex-almighty" class="post-tag" title="show questions tagged &#39;regex-almighty&#39;" rel="tag">regex-almighty</a>, like:</p>
  
  <pre><code>function parseFloat($string)
  {
     $string = (string)$string;
     if(preg_match('/^[+-]?(\d+|\d+\.\d*)[Ee]([+-]?)(\d+)$/', $string, $matches))
     {
        $precision = false!==($dot=strpos($matches[1], '.'))
                     ?strlen($matches[1])-$dot-1
                     :0;
        $precision = $matches[2]=='-'
                     ?$precision + (int)$matches[3]
                     :$precision - (int)$matches[3];
        return number_format($string, $precision&lt;0?0:$precision, '', '');
     }
     if(preg_match('/^[+-]?(\d+|\d+\.\d+)$/', $string))
     {
        return $string;
     }
  }
  </code></pre>
  
  <p><strong>The question</strong></p>
  
  <p>I feel that there should be more simple and wise way to do that. How to achieve that in more simple way in PHP? May be some tricky <a href="http://php.net/sprintf" rel="nofollow noreferrer"><code>sprintf()</code></a> format?</p>
  
  <p><em>Important note</em>: I don't want to deal with precision. I want black box. Pass something numeric there - got string as output. That's all. Don't want to deal with anything else. In fact, all my regex are about calculating length &amp; precision - so, sure, if pass them explicitly (as parameters, for example) - we cat get rid of regex. But - no, that's not what I want.</p>