sprintf (or other function) for contitional formatting of integer / float
<p>I need to display a number registered in database as a float</p>

<p>If the number ha no decimal part, is should be displayed as an int, and as a decimal in other cases.</p>

<p>Example : </p>

<pre><code>8.00 should be displayed 8
8.45 should be displayed 8.45
</code></pre>

<p>The existing code uses a weird (but functionnal solution) using roud() : </p>

<pre><code>if(round($number) == $number) {
 $number = round($number);
}
</code></pre>

<p>I wish to find some solution with sprintf by example, to have a more self-explicating code (the actual solution with round is not very understandable)</p>

<p>Does any of you faced this problem and knows a solution
(I've tried to play with sprintf() but I dit not managed how to have a variable number of decimals)</p>
