Post the output.
Also, there is a space here
Also, there is a space here
'{}'. format('$' + str(taxableequity))
which souldn't be there
Formatting $
|
Post the output.
Also, there is a space here '{}'. format('$' + str(taxableequity)) which souldn't be there
Here is some of the output: (When I copy and paste, the spaces (tabs) between the three sets of numbers disappear and the numbers run together - do not know why -- they show up on my output but not when copy and paste)
Year Your Spouse Taxable Taxable Taxable Age Age Equity Fixed Income Cash 2017 62 61 $100000 200000 50000 2018 63 62 $105000.0 212000.0 52000.0 2019 64 63 $110250.0 224720.0 54080.0 2020 65 64 $115762.5 238203.2 56243.200000000004 2021 66 65 $121550.625 252495.392 58492.92800000001 2022 67 66 $127628.15625 267645.115 60832.64512000001 2023 68 67 $134009.5640625 283703.822 63265.95092480001 2024 69 68 $140710.042265625 300726.051 65796.58896179202 2025 70 69 $147745.54437890626 318769.614 68428.4525202637 2026 71 70 $155132.82159785158 337895.791 71165.59062107425 2027 72 71 $162889.46267774416 358169.539 74012.21424591723 2028 73 72 $171033.93581163138 379659.711 76972.70281575392 2029 74 73 $179585.63260221295 402439.294 80051.61092838408 2030 75 74 $188564.91423232362 426585.652 83253.67536551945 2031 76 75 $197993.1599439398 452180.791 86583.82238014023 2032 77 76 $207892.8179411368 479311.638 90047.17527534584 2033 78 77 $218287.45883819365 508070.336 93649.06228635968 2034 79 78 $229201.83178010333 538554.557 97395.02477781408 2035 80 79 $240661.9233691085 570867.830 101290.82576892665 2036 81 80 $252695.01953756393 605119.900 105342.45879968372 2037 82 81 $265329.7705144421 641427.094 109556.15715167107 2038 83 82 $278596.25904016424 679912.720 113938.40343773791 2039 84 83 $292526.07199217245 720707.483 118495.93957524744
Dec-25-2016, 01:15 PM
Did you try
round(num) ? See the example I've wrote.>>> xyz = 1.234 >>> '{}'.format(('$' + str(round(xyz))).rjust(10, ' ')) ' $1.0' >>>
I actually did try to put ROUND, but did not know enough about the language to know where to locate it in the line of code.
What part of the line of code you wrote would I change to get no decimal places? thanks for the reply. Happy holidays. I tried your line; got this Traceback (most recent call last): File "C:/Users/Dennis/PycharmProjects/untitled1/savings.py", line 62, in <module> '{}'.format(('$' + str(round(taxableequity))).rjust(10, ' ')), "\t", TypeError: type str doesn't define __round__ methodI am sorry to keep bothering you -- I appreciate the responses
That is because
taxableequity isn't a number but a string and you can't use round() over strings.
Dec-25-2016, 05:43 PM
I got it !!!! Well most of it. I rounded before writing to the file; now when I read it, it comes out correct. I just have to figure out how to format a comma when numbers get over 1,000
thanks again
Well, look at this
>>> num = '1234567890' >>> "{0:,d}".format(int(num)) '1,234,567,890' >>>Also, you might be interested from locale module. It can handle currency formatting. https://docs.python.org/3.5/library/locale.html
Dec-25-2016, 08:51 PM
I should have been more specific : I am trying to format a 'string' of numbers with a comma using the format statement you gave me:
'{}'.format(('$' + taxableequity).rjust(12, ' '))It works perfect, except no comma.
I am aware.
You can put the comas before formatting it with the dollar sign. Or just to use "{0:,d}".format(int(taxableequity)) here "$" + taxableequity in place of taxableequity variable itself. Wrapped with the proper data types.
|
|