Format number to N significant digits in PHP
<p>I would like to format (round) float (double) numbers to lets say 2 significant digits for example like this:</p>

<pre><code>1        =&gt; 1
11       =&gt; 11
111      =&gt; 110
119      =&gt; 120
0.11     =&gt; 0.11
0.00011  =&gt; 0.00011
0.000111 =&gt; 0.00011
</code></pre>

<p>So the arbitrary precision remains same</p>

<p>I expect there is some nice function for it already built in, but could not find any so far</p>

<p>I was pointed to <a href="https://stackoverflow.com/questions/5834537/how-to-round-down-to-the-nearest-significant-figure-in-php">How to round down to the nearest significant figure in php</a>, which is close but doesn't work for N significant digits and I'm not sure what it does with 0.000XXX numbers </p>