I have a question relating to the output of a program.
def writeOutput():
output.write(str(gallons) + '\n')
output.write(str(usage) + '\n')
output.write(str(sewer) + '\n')
output.write(str(tax) + '\n')
output.write(str(total) + '\n')
output.write('_______________________' + '\n')
This is my write to file function.
Does anybody know where I can look to find out how to write 123.45 as “123 dollars 45 cents” with dollars and cents spelled out like that?
Thanks!
If you have
amountstored as afloat(*), you can use the%formatting operator as follows:or
(*) Which you should never do in a real financial app, since floating point is prone to rounding errors; use the
Decimalmodule instead.