投資の複利が計算できるプログラム
ソースコード
javascriptを使用しています。
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
body{
padding:10px;
}
</style>
<script type="text/javascript">
function Calculator() {
rate = document.myform.rate.value;
amount = parseInt(document.myform.amount.value, 10);
period = parseInt(document.myform.period.value, 10);
// document.myform.receipt.value = fukuri(rate, amount, period);
tesuu = document.myform.tesuu.value / 100;
receipt = fukuri(rate, amount, period,tesuu);
}
function fukuri(rate, amount, period,tesuu) {
var receipt;
receipt = amount;
var str = "";
str += "<table class=table>";
str += "<tr><th>預入期間</th><th>元金+利益</th><th>運用手数料</th><th>最終合計</th></tr>";
//預入金額=元金×(1+金利)/100
//Math.round:小数点以下を四捨五入
for (var i = 1; i <= period; i++) {
receipt = Math.round(receipt * (1 + rate / 100));
tesuu2 = parseInt(tesuu * receipt , 10);
last = receipt - tesuu2;
str += "<tr><td>" + i + "年</td><td>" + receipt + "円</td><td>" + tesuu2 + "円</td><td>" + last + "円</td></tr>";
receipt = last;
}
str += "</table>";
document.getElementById("result").innerHTML = str;
return receipt;
}
function TableClear() {
document.getElementById("result").innerHTML = "";
}
</script>
<form name="myform">
<table class="table">
<tr>
<th>金利</th>
<td><input type="text" name="rate" size="22" value="5" />%</td>
</tr>
<tr>
<th>金額</th>
<td><input type="text" name="amount" size="22" value="1000000" />円</td>
</tr>
<tr>
<th>期間</th>
<td><input type="text" name="period" size="22" value="10" />年</td>
</tr>
<tr>
<th>運用手数料</th>
<td><input type="text" name="tesuu" size="22" value="0.1" />%</td>
</tr>
</table>
<input type="button" onclick="Calculator()" value="計算" /> <input type="reset" onclick="TableClear()" value="クリア" />
</form>
<hr />
<div id="result"></div>
コメント
[…] javascriptで複利計算プログラム投資の複利が計算できるプログラムソースコ… […]