DillonCarter
DillonCarter

Reputation: 97

Can't calculate compound interest correctly

Here is the code:

def calculate(*args):
try:
    value = float(income.get())
    expenses.set("$"+str(value * .60))
    longTerm.set("$"+str(value * .10))
    vacation.set("$"+str(value * .04))
    carDown.set("$"+str(value * .04))
    homeDown.set("$"+str(value * .02))
    guiltFree.set("$"+str(value * .20))
    projection.set("$"+str(value * .10 * 1 + 0.05/4 ** 4*10))

except ValueError:
    pass

For some reason, the output when I pass in 100 is $100.001953125

What am I doing wrong in the projection.set section of code for the math?

Upvotes: 0

Views: 57

Answers (1)

John Coleman
John Coleman

Reputation: 51998

I'm not 100% sure what you are trying to do, but I you want to implement the formula

A = P(1+r/m)^mt

You would need

projection.set("$"+str(value * .10 *( 1 + 0.05/4) ** (4*10)))

rather than

projection.set("$"+str(value * .10 * 1 + 0.05/4 ** 4*10))

(Remember PEMDAS)

Upvotes: 1

Related Questions