Skip to content

Instantly share code, notes, and snippets.

@luchenqun
Created February 23, 2021 02:45
Show Gist options
  • Select an option

  • Save luchenqun/642171a6b2349f46895fa656cb313747 to your computer and use it in GitHub Desktop.

Select an option

Save luchenqun/642171a6b2349f46895fa656cb313747 to your computer and use it in GitHub Desktop.
贷款计算
// 参数设置,按照你的实际参数修改
const year = 30; // 贷款多少年年
const loan = 700000; // 总共借贷金额
const perMonthLoan = 3510; // 每月还贷金额
const yearRate = 0.038; // 假设我存到银行年利率
const perMonthDeposit = 6; // 每几(6)个月存一次
// 如果把贷款得钱存银行
let count = 12 * year / perMonthDeposit; // 能存多少次
const rate = yearRate / 12 * perMonthDeposit; // 算出存到银行得利率
let total = loan;
let month = 1;
while(count > 0) {
total = total * rate + total;
count -= 1;
console.log(`第${perMonthDeposit * month++}个月手上资金:`, total.toFixed(2));
}
// 计算结果比较
console.log(`每月还${perMonthLoan}一共需要还的钱:`, (perMonthLoan * 12 * year).toFixed(2));
console.log(`每${perMonthDeposit}月一存按年利率${yearRate}计算30年后总资金:`, total.toFixed(2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment