How do I format currency in Java without unnecessary trailing zeroes? [duplicate]

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.

Thanks