Im currently writing a program in python and i need to be able to truncate the number after 2 decimal places and align it in a table. However, i am unsure how to truncate AND pad my output. Here is the code i want to alter that currently has truncation.
print(month_count,'\t','\t',monthly_payment,'\t','\t',"%.2f" % '%d' % interest_amount,'\t','\t',"%.2f" % loan)
You might want to use
.format()
for both truncation and alignment:>10
part means right adjusted with total of 10 characters..2f
means keep only 2 decimal places.See https://pyformat.info/ for more