一般信用贷款会提供两种还款方式:每月等额或者先息后本。每月等额,就是每月归还等同的部分本金和利息,你手里在使用的本金其实是逐月减少的。先息后本就是先还利息,到期归还本金。
每月等额
?
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
/**
* <p>Title: 等额本息还款工具类</p>
*
*/
public class CPMUtils{
/**
* <p>Description: 每月还款总额。〔贷款本金×月利率×(1+月利率)^还款月数〕÷〔(1+月利率)^还款月数-1〕</p>
* @param principal 贷款本金
* @param monthlyInterestRate 月利率
* @param amount 期数
* @return
*/
public static BigDecimal monthlyRepayment(BigDecimal principal, BigDecimal monthlyInterestRate, int amount){
//(1+月利率)^还款月数
BigDecimal temp = monthlyInterestRate.add(MoneyUtils.ONE).pow(amount);
return principal.multiply(monthlyInterestRate)
.multiply(temp)
.divide(temp.subtract(MoneyUtils.ONE), MoneyUtils.MATHCONTEXT);
}
/**
* <p>Description: 月还款利息。(贷款本金×月利率-月还款额)*(1+月利率)^(当前期数-1)+月还款额</p>
* @param principal 贷款本金
* @param monthlyInterestRate 月利率
* @param monthlyRepayment 月还款额
* @param number 当前期数
* @return
*/
public static BigDecimal monthlyInterest(BigDecimal principal, BigDecimal monthlyInterestRate, BigDecimal monthlyRepayment, int number){
//(1+月利率)^(当前期数-1)
BigDecimal temp = monthlyInterestRate.add(MoneyUtils.ONE).pow(number - 1 );
return principal.multiply(monthlyInterestRate)
.subtract(monthlyRepayment)
.multiply(temp).add(monthlyRepayment, MoneyUtils.MATHCONTEXT);
}
/**
* <p>Description: 还款总利息。期数×贷款本金×月利率×(1+月利率)^期数÷〔(1+月利率)^期数-1〕-贷款本金 </p>
* @param principal 贷款本金
* @param monthlyInterestRate 月利率
* @param amount 还款期数
* @return
*/
public static BigDecimal interest(BigDecimal principal, BigDecimal monthlyInterestRate, int amount){
//(1+月利率)^期数
BigDecimal temp = monthlyInterestRate.add(MoneyUtils.ONE).pow(amount);
return new BigDecimal(amount)
.multiply(principal)
.multiply(monthlyInterestRate)
.multiply(temp)
.divide(temp.subtract(MoneyUtils.ONE), MoneyUtils.MATHCONTEXT)
.subtract(principal, MoneyUtils.MATHCONTEXT);
}
/**
* <p>Description: 月还款本金。已经精确到分位,未做单位换算</p>
* @param principal 贷款本金
* @param monthlyInterestRate 月利率
* @param monthlyRepayment 月还款额
* @param number 当前期数
* @return
*/
public static BigDecimal monthlyPrincipal(BigDecimal principal, BigDecimal monthlyInterestRate, BigDecimal monthlyRepayment, int number){
BigDecimal monthInterest = monthlyInterest(principal, monthlyInterestRate, monthlyRepayment, number);
//月还款额-月还款利息
return monthlyRepayment.subtract(monthInterest).setScale(MoneyUtils.MONEYSHOWSCALE, MoneyUtils.SAVEROUNDINGMODE);
}
/**
* <p>Description: 月还款本金。已经精确到分位,未做单位换算</p>
* @param monthRepayment 月还款总额
* @param monthInterest 月还款利息
* @return
*/
public static BigDecimal monthPrincipal(BigDecimal monthRepayment, BigDecimal monthInterest){
//月还款总额-月还款利息
return monthRepayment.subtract(monthInterest).setScale(MoneyUtils.MONEYSHOWSCALE, MoneyUtils.SAVEROUNDINGMODE);
}
}
|
先息后本
?
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
|
import java.math.BigDecimal;
/**
* <p>Title: 先息后本还款方式工具类型</p>
*/
public class BIAPPUtils extends RepaymentUtils {
/**
* <p>Description: 月还款利息 贷款本金×月利率 </p>
* @param loan 贷款本金
* @param monthlyInterestRate 月利率
* @return
*/
public static BigDecimal monthlyInterest(BigDecimal loan, BigDecimal monthlyInterestRate){
return loan.multiply(monthlyInterestRate, MoneyUtils.MATHCONTEXT);
}
/**
* <p>Description: 还款总利息 贷款本金×月利率×期数</p>
* @param loan 贷款本金
* @param monthlyInterestRate 月利率
* @param number 期数
* @return
*/
public static BigDecimal interest(BigDecimal loan, BigDecimal monthlyInterestRate, int number){
return loan.multiply(monthlyInterestRate).multiply( new BigDecimal(number), MoneyUtils.MATHCONTEXT);
}
/**
* <p>Description: 月还款额</p>
* @param loan 贷款本金
* @param monthlyInterestRate 月利率
* @param amount 期数
* @param curNumber 当前期数
* @return
*/
public static BigDecimal monthlyRepayment(BigDecimal loan, BigDecimal monthlyInterestRate, int amount, int curNumber){
BigDecimal monthlyInterest = monthlyInterest(loan, monthlyInterestRate);
if (amount == curNumber){
return monthlyInterest.add(loan, MoneyUtils.MATHCONTEXT); //最后月还款额
} else {
return monthlyInterest;
}
}
}
|
*金额计算工具类
?
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|