等额本金还款

等额本金:每月的还款额不同,呈现逐月递减的状态;它是将贷款本金按还款的总月数均分,再加上上期剩余本金的利息,这样就形成月还款额,所以等额本金法第一个月的还款额最多,然后逐月减少,越还越少。

 

/**
	 * 等额本金还款法
	 * @param _loanAmount 贷款金额(元)
	 * @param _loanYears 贷款年数
	 * @param _annualInterestRate 贷款年利率(%)
	 */
	private static void averageCapital(double _loanAmount, int _loanYears, double _annualInterestRate){
		BigDecimal digit_0 = new BigDecimal(0); //数字0
		BigDecimal digit_100 = new BigDecimal(100); //数字100
		BigDecimal monthsOfYear = new BigDecimal(12); //一年的月数
		int scale = 10; //精度
		
		BigDecimal loanTotal = new BigDecimal(_loanAmount);	//贷款总额,元为单位
		BigDecimal loanYears = new BigDecimal(_loanYears); //贷款年数
		BigDecimal annualInterestRate = new BigDecimal(_annualInterestRate).divide(digit_100); //年利率
		
		//还款月数
		int loanMonths = loanYears.multiply(monthsOfYear).intValue();
		System.out.println("还款月数:" + loanMonths);
		
		//月利率 = 年利率 /12。一般以千分之表示
		BigDecimal monthlyInterestRate = annualInterestRate.divide(monthsOfYear, scale, BigDecimal.ROUND_HALF_UP);
		System.out.println("月利率:" + toFixed(monthlyInterestRate.multiply(new BigDecimal(1000)), 3));
		
		//每月本金=总本金/还款月数
		BigDecimal monthlyPrincipal = loanTotal.divide(new BigDecimal(loanMonths), scale, BigDecimal.ROUND_HALF_UP);
		
		BigDecimal accruedPrincipal = digit_0; //累计本金
		BigDecimal totalInterest = digit_0; //累计利息

		System.out.println("\n期数,还款本息(元),还款利息(元),还款本金(元),剩余本金(元)");
		for(int n=1; n<=loanMonths; n++){
			//每月还款本息 =(本金/还款月数)+(本金-累计已还本金)×月利率
			BigDecimal bx1 = loanTotal.divide(new BigDecimal(loanMonths), scale, BigDecimal.ROUND_HALF_UP);
			BigDecimal bx2 = loanTotal.subtract(accruedPrincipal).multiply(monthlyInterestRate);
			BigDecimal monthlyRepaymentAmount = bx1.add(bx2);
			
			//每月利息 = (本金-累计已还本金)×月利率
			BigDecimal lx = loanTotal.subtract(accruedPrincipal).multiply(monthlyInterestRate);
			
			//总利息
			totalInterest = totalInterest.add(lx);
				
			//累计已还本金
			accruedPrincipal = accruedPrincipal.add(monthlyPrincipal);
			
			//剩余本金 = 本金-累计已还本金
			BigDecimal remainingPrincipal = loanTotal.subtract(accruedPrincipal);
				
			System.out.println(n + "," + toFixed(monthlyRepaymentAmount, 2) + "," + toFixed(lx, 2) + "," + toFixed(monthlyPrincipal, 2) + "," + toFixed(remainingPrincipal, 2));
		}
		
		System.out.println("总利息:" + toFixed(totalInterest, 2));
		System.out.println("还款总金额:" + toFixed(loanTotal.add(totalInterest), 2));
	}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值