-
Notifications
You must be signed in to change notification settings - Fork 0
/
fd.html
executable file
·117 lines (114 loc) · 4.01 KB
/
fd.html
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
<html>
<style>
input[type="text"]
{
width:80px;
}
</style>
<title>房贷计算器</title>
<body>
<div></div>
公积金贷款额度: <input type="text" id="gded" maxlength="4" onkeypress='return event.charCode>=48 && event.charCode<=57'/> 万元
</br></br>
商业贷款额度:  <input type="text" id="sded" maxlength="4" onkeypress='return event.charCode>=48 && event.charCode<=57'/> 万元
</br></br>
贷款年限:  <input type="text" id="year" maxlength="2" onkeypress='return event.charCode>=48 && event.charCode<=57'/> 年
</br></br>
公积金利率: <input type="text" id="gdll" maxlength="4" onkeypress='return (event.charCode>=48 && event.charCode<=57)||event.charCode==0x2e' value="3.25"/> %
</br></br>
商贷利率:  <input type="text" id="sdll" maxlength="4" onkeypress='return (event.charCode>=48 && event.charCode<=57)||event.charCode==0x2e' value="4.9"/> %
商贷折扣<input type="text" id="discount" maxlength="3" onkeypress='return (event.charCode>=48 && event.charCode<=57)' value="100"/>
</br></br>
<input type="button" value="计算" onclick="calc()"/>
<div id="result">
</div>
<script type="text/javascript">
function getbenjinfirst(ed, ir, year) {
bj=ed*10000.0/12.0/year;
lx=ed*10000.0*ir;
return [bj,lx];
}
function getbenxifirst(ed, ir, year) {
bj=ed*10000.0*ir/(Math.pow(1+ir, year*12)-1);
lx=ed*10000.0*ir;
return [bj,lx]
}
function calc() {
gded = document.getElementById('gded');
sded = document.getElementById('sded');
year = document.getElementById('year');
gdll = document.getElementById('gdll');
sdll = document.getElementById('sdll');
discount = document.getElementById('discount');
var i_gded=0
var i_sded=0
var i_year=0
var i_gdll=3.25
var i_sdll=4.9
if (!gded.value && !sded.value) {
alert("input one aleast");
return;
}
if (gded.value) {
i_gded=parseFloat(gded.value)
}
if (sded.value) {
i_sded=parseFloat(sded.value)
}
year = document.getElementById('year');
if (!year.value || "0"==year.value) {
alert("please input valid year");
return;
}
i_year=parseInt(year.value)
i_gdll=parseFloat(gdll.value)
i_sdll=parseFloat(sdll.value)*parseFloat(discount.value)/100.0
i_gdyl = i_gdll/100.0/12.0
i_sdyl = i_sdll/100.0/12.0
bjs = getbenjinfirst(i_sded, i_sdyl, i_year)
bjg = getbenjinfirst(i_gded, i_gdyl, i_year)
bxs = getbenxifirst(i_sded, i_sdyl, i_year)
bxg = getbenxifirst(i_gded, i_gdyl, i_year)
var result=document.getElementById('result');
var html="first db:</br>";
var html="<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">";
html+="<tr>";
html+="<td>方式</td>";
html+="<td colspan=\"2\" align=\"center\">等额本息</td>";
html+="<td colspan=\"2\" align=\"center\">等额本金</td>";
html+="</tr>";
html+="<tr>";
html+="<td></td>";
html+="<td>首月还款</td>";
html+="<td align=\"center\">总利息</td>";
html+="<td>首月还款</td>";
html+="<td align=\"center\">总利息</td>";
html+="</tr>";
html+="<tr>";
html+="<td></td>";
html+="<td>"+Math.round(bxs[0]+bxs[1]+bxg[0]+bxg[1])+"</td>";
html+="<td>"+Math.round((bxs[0]+bxs[1]+bxg[0]+bxg[1])*12*i_year-i_sded*10000-i_gded*10000)+"</td>";
html+="<td>"+Math.round(bjs[0]+bjs[1]+bjg[0]+bjg[1])+"</td>";
html+="<td>"+Math.round(i_year*12.0*(bjs[0]+bjs[1])-i_year*12*(i_year*12-1)*bjs[0]*i_sdyl/2 + i_year*12.0*(bjg[0]+bjg[1])-i_year*12*(i_year*12-1)*bjg[0]*i_gdyl/2-i_sded*10000-i_gded*10000)+"</td>";
html+="</tr>";
html+="<tr>";
html+="<td>年份</td>";
html+="<td>还款额度</td>";
html+="<td>剩余本金</td>";
html+="<td>还款额度</td>";
html+="<td>剩余本金</td>";
html+="</tr>";
for (var N=1; N<=i_year; N++) {
html+="<tr><td>"+N+"</td>";
html+="<td>"+Math.round(N*12.0*(bxs[0]+bxs[1]+bxg[0]+bxg[0]))+"</td>";
html+="<td>"+Math.round(10000.0*(i_sded+i_gded) - bxs[0]*(Math.pow((1+i_sdyl),(N*12))-1)/i_sdyl - bxg[0]*(Math.pow((1+i_gdyl),(N*12))-1)/i_gdyl)+"</td>";
html+="<td>"+Math.round(N*12.0*(bjs[0]+bjs[1])-N*12*(N*12-1)*bjs[0]*i_sdyl/2 + N*12.0*(bjg[0]+bjg[1])-N*12*(N*12-1)*bjg[0]*i_gdyl/2)+"</td>";
html+="<td>"+Math.round(10000.0*(i_sded+i_gded)-N*12.0*(bjs[0]+bjg[0]))+"</td>";
html+="</tr>"
}
html+="</table>";
result.innerHTML = html;
}
</script>
<body>
</html>