javascript 如何在javascript中计算抵押贷款
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17101442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to calculate mortgage in javascript
提问by steve
I have formula for finding monthly payment with four fields
我有四个字段查找每月付款的公式
- Loan Amount
- Interest Rate
- Terms of loan
- Monthly Payment
- 贷款额度
- 利率
- 贷款条款
- 每月支付
Formula: Monthly Payment =Loan amount * ((1 + Interest rate per annum/100) ^ Term of loan) / Term of loan / 12
Formula: Monthly Payment =Loan amount * ((1 + Interest rate per annum/100) ^ Term of loan) / Term of loan / 12
Now I want to find
现在我想找到
- Loan Amount
- Interest Rate
- Terms of loan
- 贷款额度
- 利率
- 贷款条款
if any of three fields are populated.
如果填充了三个字段中的任何一个。
I have also formula for calculating loan amount based on interest rate, terms of loan and monthly payment.
我还有根据利率、贷款条款和每月付款计算贷款金额的公式。
Formula: Loan amount = Monthly Payment/ ((1 + Interest rate per annum/100) ^ Term of loan) * Term of loan * 12
But it does not calculating perfect figure.
但它不计算完美的数字。
Any one can give me these three formulas for calculating loan amount/interest rate/terms of loan (java script will be more appreciated)
任何人都可以给我这三个计算贷款金额/利率/贷款条款的公式(java脚本会更受欢迎)
回答by shay
Here is mine,
这是我的,
the formula :
公式 :
M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
Hope this helps in someway
希望这在某种程度上有所帮助
var M; //monthly mortgage payment
var P = 400000; //principle / initial amount borrowed
var I = 3.5 / 100 / 12; //monthly interest rate
var N = 30 * 12; //number of payments months
//monthly mortgage payment
M = monthlyPayment(P, N, I);
console.log(M);
function monthlyPayment(p, n, i) {
return p * i * (Math.pow(1 + i, n)) / (Math.pow(1 + i, n) - 1);
}
回答by kishoredbn
var deno = (100 + Interest_rate_per_annum)/100;
var pdeno = Math.pow(deno, Term_of_Loan);
var loan_amount = (Monthly_payment * Term_of_Loan * 12) / pdeno;
回答by John Langford
This is the exact same answer as @shay gave but with the variable names spelled out to make it easier for me to understand:
这与@shay 给出的答案完全相同,但拼写了变量名称,以便我更容易理解:
// totalPayments should be the total number of payments expected to be made for the life of the loan: years * 12
// interestRate: eg. 6.2% should be passed as 0.062
function getMortgagePayment(startingLoanAmount, totalPayments, interestRate)
{
let interestRatePerMonth = interestRate / 12;
return startingLoanAmount * interestRatePerMonth * (Math.pow(1 + interestRatePerMonth, totalPayments)) / (Math.pow(1 + interestRatePerMonth, totalPayments) - 1);
}