Format float to show decimal places if is not zero java
<p>I need to to show decimal places of a float value only when it is different from zeros.</p>

<ol>
<li><strong>5.0</strong> should be shown as <strong>5</strong>.</li>
<li><strong>7.3</strong> should be shown as <strong>7.3</strong>.</li>
<li><strong>9.000003</strong> should be shown as <strong>9.000003</strong>.</li>
</ol>

<p>How to format in this way using regex or DecimalFormat?</p>