☆☆ 新着記事 ☆☆
2018年6月18日月曜日
Javascript Loan 月額支払計算式
1. 定期支払額
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var rate = 0.04;
var loan_amt = 100000;
var months = 60;
var month_rate = rate/12
var compound_int = Math.pow (1 + month_rate, months);
var monthly = (loan_amt*compound_int*month_rate)/(compound_int-1)
console.log(monthly)
</script>
</head>
<body>
</body>
</html>
====具体例===
function startOver() {
document.loan_form.loan_amt.value="0";
document.loan_form.months.value="0";
document.loan_form.rate.value="0";
document.loan_form.extra.value="";
document.getElementById("loan_info").innerHTML = "";
document.getElementById("table").innerHTML = "";
}
function validate(){
var loan_amt = document.loan_form.loan_amt.value;
var months = document.loan_form.months.value;
var rate = document.loan_form.rate.value;
var extra = document.loan_form.extra.value;
if(loan_amt <= 0 || isNaN(Number(loan_amt))){
alert("please enter a valid loan amount.");
document.loan_form.loan_amt.value = "0";
}
else if (months <=0 || parseInt(months) != months){
alert("please enter a valid number of months.");
document.loan_form.months.value = "0";
}
else if (rate <= 0 || isNaN(Number(rate))){
alert("please enter a valid interest rate.");
document.loan_form.loan_amt.value = "0";
}
else if (extra < 0 || isNaN(Number(extra))){
alert("please enter a valid extra payment.");
document.loan_form.loan_amt.value = "0";
}
else{
alert("validation complete");
alert(parseFloat(loan_amt) +'/n'+ parseInt(months))
calculate(parseFloat(loan_amt),parseInt(months),parseFloat(rate),parseFloat(extra));
// calculate function()に渡すvaluewを()内で指定
//str型から其々の数字に
}
}
function calculate(loan_amt,months,rate,extra){
i = rate/100
var monthly_pmt = loan_amt*(i/12)*Math.pow((1+i/12), months)/(Math.pow((1+i/12), months)-1);
alert(round(monthly_pmt,2));
}
function round(num,dec){ //小数点での四捨五入
return (Math.round(num*Math.pow(10,dec))/Math.pow(10,dec)).toFixed(dec);
}
}
2. 最大借入額
<head>
<!-- Forumula-->
P =(R/(1-(1+R)^-N))*Loan
P is the constant payment you make every period
R is the interest rate per period
N is the number of periods
Loan is the total loan amount
-->
<script type="text/javascript">
function month_pmt(){
var R = 0.04/12;
var N = 360;
var Loan = 100000;
var Compound_int = Math.pow((1+R),-N);
P = ((R)/(1-Compound_int))*Loan
document.write(P);
}
function reg_pmt(){ var r = 0.04/12;
var n = 360;
var p = 300
var compound_int = Math.pow((1+r),-n);
Loan = p/((r)/(1-compound_int));
document.write(Loan);
}
month_pmt()
document.write("aaa")
reg_pmt()
</script>
</head>
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿