1
我要做的攤銷時間表和輸出應該是:在幾年 抵押期限 按揭利率 按揭量 總利息金額 按揭總額爲什麼total_loan不工作(是一樣的total_interest),也IDK如何顯示時間表正確
每月的按揭付款&按揭貸款餘額每月。 如果餘額爲0打印「這是終止攤銷計算器......」
謝謝!
<script>
var I = 0.0575;
var total_interest;
var total_loan;
var balance;
var P = parseFloat(prompt("Enter the loan amount $:", 0));
var Y = parseInt(prompt("Enter the term years ('30 or 15'):", 0));
var termMonths = Y * 12;
//if(Y != "30" || Y != "15"){
// alert("Please enter the term years: '30 or 15'");
// var Y = parseInt(prompt("Enter the term years ('30 or 15'):",0));
var month_payment = (((I/12) * P)/(1 - (Math.pow(1 + (I/12), (Y * -12))))).toFixed(2);
total_interest = parseFloat((month_payment * termMonths) - P).toFixed(2);
total_loan = parseFloat(total_interest + P).toFixed(2);
document.write("Mortgage term in years:", +Y + "<br>");
document.write("Mortgage Interest Rate: " + I + "<br>");
document.write("Mortgage amount: $" + P + "<br>");
document.write("Total Interest Amount: $" + total_interest + "<br>");
document.write("Total Mortgage Amount: $" + total_loan + "<br><br>");
var numPayments = 12 * Y;
for (var i = 0; i <= numPayments; i++) {
balance = parseFloat(total_loan - month_payment).toFixed(2);
document.write("Monthly Mortgage Payments: $" + month_payment + " & Mortgage Loan Balance for each month: $" + balance + "<br>");
}
if (balance == 0) {
document.write("This is the Ending Amortization Calculator......")
}
</script>
謝謝你現在@jeron我知道了! 另外,你知道那條線有什麼問題嗎?因爲total_interest + P總和不起作用。 total_loan = parseFloat(total_interest + P).toFixed(2); –
你確定它不起作用嗎?當我爲P投入500,000美元時,total_loan給我550429.60美元。你期望的數字是多少? – jeron
因爲她給了我們這些公式: 總利息金額是月付款x期數月 - 貸款金額。 貸款總額+貸款總額。 因此,如果我的貸款額度是5萬美元,並且我在30年內每月支付300美元,那麼在幾個月內應該是300 *期 - 50,000是正確的? 然後總貸款應該是50,000 +總利息。 total_loan和total_interest的數量不能相同。我錯了嗎? –