Format string with no decimals OR 2 decimals
<p>I have a float number. I want to convert it to a string with the following two rules</p>

<ul>
<li>If the float has no decimal part then do not create any decimal part</li>
<li>If the float has a decimal part then convert it to two decimal places</li>
</ul>

<p>For example</p>

<pre><code>499 =&gt; "499"
499.5 =&gt; "499.50"
499.99 =&gt; "499.99"
499.989 =&gt; "499.99"
</code></pre>

<p>How would you do that in php?</p>
