等额本息还款,也称定期付息,即借款人每月按相等的金额偿还贷款本息,其中每月贷款利息按月初剩余贷款本金计算并逐月结清。把按揭贷款的本金总额与利息总额相加,然后平均分摊到还款期限的每个月中。作为还款人,每个月还给银行固定金额,但每月还款额中的本金比重逐月递增、利息比重逐月递减。
每月还款额计算公式如下:
每月还款额=[贷款本金×月利率×(1+月利率)^还款月数]÷[(1+月利率)^还款月数-1]
java代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| import java.math.BigDecimal;
public class PrincipalAndInterestEquals {
public static void main(String[] args) { BigDecimal invest = new BigDecimal(139000); double yearRate = 0.059; int year = 15; double monthRate = yearRate / 12; int month = year * 12; BigDecimal monthIncome = invest.multiply(new BigDecimal(monthRate * Math.pow(1 + monthRate, month))).divide(new BigDecimal(Math.pow(1 + monthRate, month) - 1), 2, BigDecimal.ROUND_HALF_UP); System.out.println("每月本息金额 : " + monthIncome); System.out.println("---------------------------------------------------"); BigDecimal monthCapital; BigDecimal sumCapital = BigDecimal.ZERO; for (int i = 1; i < month + 1; i++) { monthCapital = invest.multiply(new BigDecimal(monthRate * (Math.pow((1 + monthRate), i - 1)))).divide(new BigDecimal(Math.pow(1 + monthRate, month) - 1), 2, BigDecimal.ROUND_HALF_UP); System.out.println("第" + i + "月本金: " + monthCapital); sumCapital = sumCapital.add(monthCapital); } System.out.println("---------------------------------------------------"); BigDecimal monthInterest; BigDecimal capital = invest; BigDecimal tmpCapital = BigDecimal.ZERO; BigDecimal sumInterest = BigDecimal.ZERO; for (int i = 1; i < month + 1; i++) { capital = capital.subtract(tmpCapital); monthInterest = capital.multiply(new BigDecimal(monthRate)).setScale(2, BigDecimal .ROUND_HALF_UP); tmpCapital = invest.multiply(new BigDecimal(monthRate * (Math.pow((1 + monthRate), i - 1)))).divide(new BigDecimal(Math.pow(1 + monthRate, month) - 1), 2, BigDecimal.ROUND_HALF_UP); System.out.println("第" + i + "月利息: " + monthInterest); sumInterest = sumInterest.add(monthInterest); } System.out.println("本金总和:" + sumCapital + " 利息总和:" + sumInterest); } }
|