Posts: 687
Threads: 37
Joined: Sep 2016
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
Posts: 53
Threads: 14
Joined: Mar 2017
(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
1 2 3 4 5 6 7 8 9 10 11 12 |
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
1 2 3 4 5 |
* * * 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
|
Posts: 3,458
Threads: 101
Joined: Sep 2016
It is rounding to the nearest 2 decimal places. But it's *also* printing the rate (2.0) before each one.
Posts: 53
Threads: 14
Joined: Mar 2017
(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
Posts: 8,167
Threads: 160
Joined: Sep 2016
(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.
|