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))
String formatting in Python: Showing a price without decimal points