This question already has an answer here:
I need to to show decimal places of a float value only when it is different from zeros.
- 5.0 should be shown as 5.
- 7.3 should be shown as 7.3.
- 9.000003 should be shown as 9.000003.
How to format in this way using regex or DecimalFormat?
To display decimals the way you desire, use the following snippet: