Python Forum
Formatting question regarding tables (Interest loan calculator)
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Formatting question regarding tables (Interest loan calculator)
#11
You typically don't use tabs for this (especially with number that should be aligned on the decimal dot). You use a format spec that force them to be padded with spaces (or something else) to achieve a specified length. So if you have at most 6 digits before the dot and 2 after (thus 9 characters totals),, you use a spec such as {:9.2f}.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#12
(May-06-2017, 10:28 PM)Ofnuts Wrote: You typically don't use tabs for this (especially with number that should be aligned on the decimal dot). You use  a format spec that force them to be padded with spaces (or something else) to achieve a specified length. So if you have at most 6 digits before the dot and 2 after (thus 9 characters totals),, you use a spec such as {:9.2f}.

Yeah I seem to be running into another problem now that it is alligned 

print("\t\t\t***Savings on initial investment of $100.00***")
print("Years\t 1 \t\t2\t\t3\t\t4\t\t5\t\t6\t\t7\t\t8\t\t9\t\t10")
years = [1,2,3,4,5,6,7,8,9,10]
rates = [2.00,2.25,2.50,3.00,3.25,3.50,4.00,4.25,5.00,5.25,5.50]
print("-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_")
principal  = 100
rate = 2.00
intrst = (rate) / 100
amount = principal
for num in years:
        amount = (amount) * (1. + intrst)
        print(rate,'%'"\t{0:.2f}".format(amount),end="")
I want it to be rounded to 2 decimal places (which it did before I added the ,end="") to it) But now it does this 

***Savings on initial investment of $100.00***
Years 1 2 3 4 5 6 7 8 9 10
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
2.0 % 102.002.0 % 104.042.0 % 106.122.0 % 108.242.0 % 110.412.0 % 112.622.0 % 114.872.0 % 117.172.0 % 119.512.0 % 121.90
Process finished with exit code 0
Reply
#13
It is rounding to the nearest 2 decimal places. But it's *also* printing the rate (2.0) before each one.
Reply
#14
(May-07-2017, 12:59 AM)nilamo Wrote: It is rounding to the nearest 2 decimal places.  But it's *also* printing the rate (2.0) before each one.

Thanks, see that now. I think I need a break lol 

https://s.aolcdn.com/dims5/amp:4612d7c10...anuary.jpg
Reply
#15
(May-06-2017, 10:28 PM)Ofnuts Wrote: You typically don't use tabs for this (especially with number that should be aligned on the decimal dot). You use  a format spec that force them to be padded with spaces (or something else) to achieve a specified length. So if you have at most 6 digits before the dot and 2 after (thus 9 characters totals),, you use a spec such as {:9.2f}.

the tab delimiter is in his homework assignment. I just merged the threads, because they are basically the same question and fixed thread title.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Formatting question Liquid_Ocelot 5 4,416 Apr-29-2017, 12:06 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020