TL;DR
print('The sales amount is $', format(salesAmount, '.2f'))
Breaking it down:
Convert the number to string formatted as 2 decimal places (.2 portion) with floating point representation (f portion).
format(salesAmount, '.2f')
Now that you have a string, you join it with either pass to print or you could join to previous code with + or whatever.
'The sales amount is $' + the_formatted_number
Answer from JBernardo on Stack Overflowpython - Need help understanding the format ".2f" command and why it is not working in my code - Stack Overflow
Using an f-string with multiple parameters (decimal places plus string padding)
What is %0.2f?
Is the format to print just 2 decimals instead of all of them when you print a float
More on reddit.comPythonic way to show 2 decimal places in f-strings?
Do the second one, just donโt worry about rounding it. Let the formatting do the rounding for display.
More on reddit.comTL;DR
print('The sales amount is $', format(salesAmount, '.2f'))
Breaking it down:
Convert the number to string formatted as 2 decimal places (.2 portion) with floating point representation (f portion).
format(salesAmount, '.2f')
Now that you have a string, you join it with either pass to print or you could join to previous code with + or whatever.
'The sales amount is $' + the_formatted_number
.2f should be outside of the format method.
eg try print("{:.2f}".format(12.345678))