create jquery compound calculator
what kind of formula is being used in the calculator mentioned below
https://www.lifeclub.com/public/calculator.aspx
i am trying to create a similar calculator using jquery. I am having a tough time getting the formula right.
how is the interest calculated on the form. what is the formula
I have 开发者_运维问答tried an attempt at it.. but my numbers do not match theirs http://jsbin.com/oxerez/edit#javascript,html,live
Total invested is initial investment and additional monthly investment.
The Total Interest Earned is for every month work out 1% interest and add it to the total, and the 1% off of that and so on.
The Average Monthly return is the all the interest added up and divided by the amount of months, 12 for 1 year, 24 for 2 years so on.
The Total Balance is the Total invest and the Total Interest Earned added together.
var initial_investment = 100,
additional_monthly_invest = 0,
interest_rate = 1,
terms_of_investment = 1,
total_invested = initial_investment,
interest_earned = 0,
total_interest_earned,
average_month_return,
total_balance,
i = terms_of_investment * 12 + 1;
while ( i -= 1 ) { // optimisation habit I've gotten into
interest_earned += ( ( ( total_invested + interest_earned ) / 100 ) * interest_rate );
total_invested += additional_monthly_invest;
}
average_month_return = interest_earned / ( terms_of_investment * 12 );
total_balance = total_invested + interest_earned;
Update: Fixed the code. I had forgotten to add some variables into the interest. Works now.
精彩评论