js 等额本息还款

这篇博客通过JavaScript展示了如何计算等额本息还款方式,包括计算月利率、每月偿还本息、每月偿还本金及利息。代码示例中详细说明了计算过程,并输出了相关结果。
摘要由CSDN通过智能技术生成

let money = 10000; // 贷款本金

let periods = 12; // 期数

let yearInterest = 18; // 年率

let month = null; // 月率

 

let monthInterest = null; // 每月偿还本息

let resultArr = []; // 每月偿还利息

let resultMoneyArr = []; // 每月偿还本金

let monthMoney = []; // 每月剩余本金

// 月率

month = parseInt(yearInterest, 10) / 100 / 12;

 

// 公式 贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数 - 1〕

let repayMonthPow = Math.pow((1 + month), periods);

monthInterest = ((money * month * repayMonthPow)/(repayMonthPow-1)).toFixed(2);

 

// 每月偿还本息

let _money = money;

for(let i = 0, len = periods; i <len; i++) {

_money-=(monthInterest - (_money * month));

monthMoney.push(parseFloat(_money.toFixed(2)));

}

 

// 每月偿还利息

resultArr = monthMoney.map((value) => {

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值