admin管理员组文章数量:1287649
I wrote small jQuery interest calulcator.
- it is calculating amount of credit from monthly re-payment
LIVE DEMO HERE
The problem is that my interest calculation logic is just purely wrong.
Have a look:
//Get the value - monhtly repayment
var InputedValue = $('form input[name="val1"]').val();
// 12 ,18, 24, 30, 36 - NumberOfMonths
for (var i = 12; i <= 36; i += 12) {
// j = 20 - Deposit in %
for (var j = 10; j <= 10; j += 10) {
// g = 20, 30 - InterestPerYear in %
for (var g = 10; g <= 10; g += 10) {
var InScaleOfYear = i / 12;
// Amount of payment excluding deposit
var AmountOfPayments = (InputedValue * (i - 1)); // rat bedzie o jedna mniej niz ilosc miesiecy, bo wplata poczatkowa
// Amount of payment including deposit
var AmountInTotal = (AmountOfPayments * 100) / (100 - j);
// Deposit
var Deposit = AmountInTotal - AmountOfPayments;
// Amount of payment in one year
var AmountOfPaymentInOneYear = (AmountOfPayments / InScaleOfYear);
var InterestPerYear = ((AmountOfPaymentInOneYear * g) / 100);
// Interest in total
var InterestInTotal = InterestPerYear * InScaleOfYear;
// Amount of credit
var AmountOfCredit = (AmountOfPayments + Deposit) - InterestInTotal;
$('table tbody').append('<tr><td>'
+ i + '</td><td>'
+ "at " + j + "% = " + Deposit.toFixed(2) + '</td><td>'
+ "at " + g + "% = " + InterestPerYear.toFixed(2) + '</td><td>'
+ "at " + g + "% = " + InterestInTotal.toFixed(2) + '</td><td>'
+ AmountOfPayments.toFixed(2) + '</td><td>'
+ AmountInTotal.toFixed(2) + '</td><td>'
+ AmountOfCredit.toFixed(2) + '</td></tr>');
}
}
}
Any of you working on something similar? How can I calculate interest having following information:
- number of month / years (
i = months
) - amount of monthly payment (
$('form input[name="val1"]').val();
) - amount of the deposit (
j = deposit
) - interest rate (
g = interest rate
)
As you can see, the loop is in place for months/deposit/interest. Just need some help with the login of calculating interest in the loop.
I wrote small jQuery interest calulcator.
- it is calculating amount of credit from monthly re-payment
LIVE DEMO HERE
The problem is that my interest calculation logic is just purely wrong.
Have a look:
//Get the value - monhtly repayment
var InputedValue = $('form input[name="val1"]').val();
// 12 ,18, 24, 30, 36 - NumberOfMonths
for (var i = 12; i <= 36; i += 12) {
// j = 20 - Deposit in %
for (var j = 10; j <= 10; j += 10) {
// g = 20, 30 - InterestPerYear in %
for (var g = 10; g <= 10; g += 10) {
var InScaleOfYear = i / 12;
// Amount of payment excluding deposit
var AmountOfPayments = (InputedValue * (i - 1)); // rat bedzie o jedna mniej niz ilosc miesiecy, bo wplata poczatkowa
// Amount of payment including deposit
var AmountInTotal = (AmountOfPayments * 100) / (100 - j);
// Deposit
var Deposit = AmountInTotal - AmountOfPayments;
// Amount of payment in one year
var AmountOfPaymentInOneYear = (AmountOfPayments / InScaleOfYear);
var InterestPerYear = ((AmountOfPaymentInOneYear * g) / 100);
// Interest in total
var InterestInTotal = InterestPerYear * InScaleOfYear;
// Amount of credit
var AmountOfCredit = (AmountOfPayments + Deposit) - InterestInTotal;
$('table tbody').append('<tr><td>'
+ i + '</td><td>'
+ "at " + j + "% = " + Deposit.toFixed(2) + '</td><td>'
+ "at " + g + "% = " + InterestPerYear.toFixed(2) + '</td><td>'
+ "at " + g + "% = " + InterestInTotal.toFixed(2) + '</td><td>'
+ AmountOfPayments.toFixed(2) + '</td><td>'
+ AmountInTotal.toFixed(2) + '</td><td>'
+ AmountOfCredit.toFixed(2) + '</td></tr>');
}
}
}
Any of you working on something similar? How can I calculate interest having following information:
- number of month / years (
i = months
) - amount of monthly payment (
$('form input[name="val1"]').val();
) - amount of the deposit (
j = deposit
) - interest rate (
g = interest rate
)
As you can see, the loop is in place for months/deposit/interest. Just need some help with the login of calculating interest in the loop.
Share Improve this question edited Oct 26, 2011 at 16:00 polarblau 17.7k8 gold badges65 silver badges84 bronze badges asked Oct 26, 2011 at 14:10 IladarsdaIladarsda 10.7k40 gold badges108 silver badges171 bronze badges 3- 2 I'm not sure if your question is actually programming related. You're looking to find a function to calculate interest based on certain variables, right? — Would that help you? math.about./od/businessmath/ss/Interest.htm – polarblau Commented Oct 26, 2011 at 16:03
- @polarblau - and how do I do that with JavaScript? – Iladarsda Commented Oct 26, 2011 at 20:12
- 3 Find out how to do it without Javascript first. The link (and many other resources online) will help you. Then translate the function into Javascript. – polarblau Commented Oct 27, 2011 at 20:18
5 Answers
Reset to default 3 +50Your wording is a little confusing. But my understanding is that you want to figure out how much credit someone can afford based on a monthly payment and some interest rate. As others have pointed out, you first need to do this on paper to make sure you have the correct formula for the type of interest and pounding period. But that's not what StackOverflow is about, we're here to focus on programming! So let's assume credit card style lending with pound interest and monthly payments (you can rewrite for any other formula as needed).
The best resource I could find online for these formulas is here: Loan or Investment Formulas. This page has the pound formula pre-solved for almost any variable! So you don't need to remember that intro to business math class from college. Nice.
So now we just need to translate the correct formula into JavaScript. This is what our StackOverflow audience wants to see! In our case, where:
- A = Total Loan Amount
- P = Monthly Payment Amount
- N = Number of Months
- i = APR Interest Rate/12
A = (P/i)[1-(1+i)^-N]
- Ok so lets change out the square brackets for normal brackets. A = (P/i)(1-(1+i)^-N)
- Now we don't want JavaScript to think that first term is a method, we want it to multiply them. So lets add the asterisk. A = (P/i) * (1 - (1+i)^-N)
- JavaScript thinks a caret is a bitwise XOR operator, so for powers lets use Math.pow() instead. A = (P/i) * (1 - Math.pow((1+i),(-N))
Done! This can work in JavaScript. How about a nice human readable sample with fortable variable names?
var MonthlyPaymentAmount = parseFloat($('#txtMonthlyPayment').val()); var APR = 16.9 / 100; //16.9% APR var InterestRate = (APR / 12); //monthly interest for (var nMonths = 12; nMonths <= 36; nMonths += 12) { var TotalAmountOfPayments = nMonths * MonthlyPaymentAmount; var TotalAmountOfCredit = (MonthlyPaymentAmount / InterestRate) * (1 - Math.pow((1 + InterestRate), (-nMonths))); var TotalAmountOfInterest = TotalAmountOfPayments - TotalAmountOfCredit; alert("Total Loan Amount: $" + TotalAmountOfCredit + "Total Paid:" + TotalAmountOfPayments + ", Interest:" + TotalAmountOfInterest); }
There you go! That'll calculate the total available credit based on some monthly payment, a given APR interest rate and 12, 24 & 36 month terms. If this wasn't exactly the goal you had in mind, go read that math tutorial and select another formula to translate to JavaScript!
The main issue is that you're trying to solve a calculus problem by using non-calculus methods. Calculus, if you aren't aware, is a branch of mathematics for essentially trying to solve for X/0 problems. In the case of pound interest, it's a case of greedy banks trying to squeeze as much money as possible from the interest.
This started out as monthly interest, but they realized that if they charged per day, they could get more. It's the same interest of say, 10% per month, divided into days as 1/3% per day. That's because the interest from the previous day is part of the calculation (or pounded) for next interest cycle. They could get more if they divided per hour, per minute, per second, until it became basically "instant interest". Thus, pound interest is born.
(Because of the popularity and confusion, the govt mandated the use of the APR term to translate the pound interest percentage into an "Annual Percentage Rate" that us normal people can relate to. So, if it says APR, and most do, it's pound interest.)
Compound interest is a X/0 problem, because you trying to get instant interest. Wikipedia's article on pound interest should provide some useful formulas for calculating pound interest. However, one important thing to remember when using formulas like these is that you can't just take something like APR and divide by 12 to get a MPR figure. Otherwise, it wouldn't be pound interest, and it's not that simple.
Try this page below, it also contains excel spreadsheet which helps greatly.
http://www.yorku.ca/amarshal/mortgage.htm
If you can follow the excel calculations in your head, you can slap out the code easily.
" I spent 4 years to graduate with a Math degree, only to have my prof tell me what I learnt is absolutely true but totally useless "
It really depends on the type of interest you're looking for (pound/simple/etc). For examples I'd look here: http://www.hotscripts./search/javascript/interest
Use the formula
A=P(1+r/n)^nt
where, A :future value with interest P :principle amount r :annual interest(decimal) n : no. of times interest is pounded per year t : no. of years for which money is invested
Convert 'r' value to float value by dividing it by 100 after accepting int value from user. Provide radio button to select type of investment like quarterly, monthly, yearly etc accordingly you can set 'n' value by using if condition.
so you can calculate any type of interest using single function.
本文标签: javascriptjQuery interest calculatorcalculate amount of credit from monthly paymentStack Overflow
版权声明:本文标题:javascript - jQuery interest calculator - calculate amount of credit from monthly payment - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741315477a2371887.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论