I would do something like this:
import decimal
a = decimal.Decimal('54.12')
b = decimal.Decimal('54.00')
for n in (a, b):
print("You have just bought an item that cost ${0:.{1}f}."
.format(n, 0 if n == n.to_integral() else 2))
{0:.{1}f} float, , 0, 2, , , , .
:
$54,12.
$54