This question already has an answer here:
JAVA How to remove trailing zeros from a double [duplicate]
How to use DecimalFormat to hide trailing zero in numbers “with decimals” only
Displaying decimals in Java without trailing zeros
How to nicely format floating numbers to String without unnecessary decimal 0?
I’m looking to output something like this
5 -> $5
5.4 -> $5.40
5.45 -> $5.45
I was hoping a format specifier can be used but any solution is good.