import kotlin.math.pow //剩余贷款金额 初始化为总贷款数 一百万 var totalLoad: Double = 1000000.0 //剩余月供期数 初始化为贷款期限 30 年 var cycle: Double = 360.0 //真是贷款期限 var totalCycle: Int = 360 //年利率 真实年利率 加点浮动可以自己计算 2019 上浮 10% val yearRate = 0.0539 //月利率 val mouthRate = yearRate / 12 //选算出来月供 [借款金额×月利率×(1+月利率)^借款月数]÷[(1+月利率)^借款月数-1] 固定公式 val monthlyPayment = (totalLoad * mouthRate * (1 + mouthRate).pow(cycle)) / ((1 + mouthRate).pow(cycle) - 1) //第一个月的利息 fun main() { var beans = ArrayList<Bean>() for (i in 1..totalCycle) { beans.add(Bean(i)) } } internal class Bean(index: Int) { init { //每个月利息为 本月还未还款金额乘月利率 var mouthInterest = totalLoad * mouthRate //本月 月供减去利息 就是还的本金 var mouthPrincipal = monthlyPayment - totalLoad * mouthRate // 总欠款-本月还款本金 为下个月待还本金 var remaining = totalLoad - mouthPrincipal if (remaining <= 0) {//最后不欠钱了 remaining = 0.0 } System.out.println("(${index}月还本金${mouthPrincipal}, 本月利息=${mouthInterest}, 剩余未还本金=${remaining})") //本金降低 这个月的本金 totalLoad = remaining //月供期数变少 cycle-- } }
等额本息的贷款计算。。后续更新 提前还款
最新推荐文章于 2023-10-31 09:44:29 发布