日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

JS信用卡真实利率计算器

發布時間:2023/12/20 javascript 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JS信用卡真实利率计算器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

算法

第一個月,還款前我手中持有現金10000元,本月我應付的利息是10000×0.66%=66元。

第二個月,因為我還了833.33元本金,還款前我手中持有現金10000-833.33=9166.67元,本月我應付的利息是9166.67×0.66%=60.5元

第三個月,我又還了833.33元本金,還款前我手中持有現金9166.67-833.33=8333.34元,本月我應付的利息是8333.34×0.66%=55元

依次類推……

第十二個月,還款前我手中僅持有833.33元,本月我應付利息833.33×0.66%=5.5元

按以上算法,我本月還欠銀行多少錢,就付相應的利息,已還部分就不應該付利息,這樣,把以上每個月利息依次相加,算出來我12個月只應該付出429元利息。

假如我持有10000元整整12個月,應該付792元利息,但我每月都在還錢,只為沒還的部分付利息,就應該付429元利息。無形中我多付了(792-429)/429*100%=84.62%。

這84.62%就是真實年利率比名義年利率多出來的部分。

那么真實年利率就是7.92%×(1+84.62%)=14.62%。

代碼

<!DOCTYPE html> <html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width"><title>信用卡真實利率計算器</title><style>body,p,span,div{font-size:12px;font-family:"MS YaHei";color:#555;margin:0;padding:0}body{background-color:#eee}p{text-align:left;width:100%}.width400{max-width:450px;width:95%}.height30{height:30px;line-height:30px}.font0{font-size:0}.to-inline-block{display:inline-block;}.aligncenter{text-align:center}.margincenter{margin:0 auto}.label{display:block;width:100%;text-align:left;font-weight:300;font-size:14px}.numbers{display:block;width:95%;margin:0 auto;border:1px solid #aaa;padding:5px;border-radius:5px;color:#ccc}.btn{height:40px;width:100%;color:#fff;background-color:#4976d6;border:0;border-radius:5px}.btn:hover{background-color:#2561e2;cursor:pointer}.output-table{margin-top:30px}.output-cell{padding:5px;font-size:14px;vertical-align:bottom;margin:-1px 0 0 -1px}.output-cell-1{width:15%}.output-cell-2,.output-cell-3,.output-cell-4{width:25%}.output-rows {margin:25px auto}.output-rows span{font-size:14px;border:1px solid #aaa;padding:10px;vertical-align:bottom;font-weight:300}#count p{margin:10px auto}#real,.header-list{background-color:#ccc;font-weight:300}#permonth>div:nth-child(2n+1){background-color:#fff}#list{background-color:#fff}.hidden{display:none}.collect{padding:10px;border:1px solid #aaa;font-size:16px;font-weight:300;margin:-1px 0 0 -1px;line-height:30px}.collect p{text-align:right;font-size:18px}</style><script>function hiddenValue(obj){var e = document.getElementById(obj);if( e.value != "" ) e.value = "";}function displayValue(obj){var e = document.getElementById(obj);if( e.value == "" ) e.value = "請不要留空!";}function count(){var ratio = parseFloat(document.getElementById( "ratio" ).value);var total = parseFloat(document.getElementById( "total" ).value);var num = parseFloat(document.getElementById( "number" ).value);console.log( "月利率="+ratio+"%\n總金額="+total+"\n期數="+num );if( isNaN(ratio) || isNaN(total) || isNaN(num) ) {window.alert("請填入有效的數字!");return;}ratio = ratio/100;//a:計算每月需還的本金,aa:計算每月利息金額var a = total/numvar aa = total*ratio;//b:計算表面的年利率var b = ratio*12//c:計算總還款額,cc:計算總還入利息var cc = aa*numvar c = total+cc//perMonth:計算還款過程中每月的真實利率, totalRatio:計算真實年利率var ratio_per_month;var totalRatio = 0;var html = "";document.getElementById( "output-table" ).classList.remove( "hidden" );for( i=0; i<num; i++ ){ratio_per_month = (total-i*a)*ratio;totalRatio += ratio_per_month;html += '<div class="body-list"><span class="to-inline-block height30 aligncenter output-cell output-cell-1">第'+(i+1)+'月</span><span class="to-inline-block height30 aligncenter output-cell output-cell-2">'+(total-(i*a)).toFixed(2)+'</span><span class="to-inline-block height30 aligncenter output-cell output-cell-3">'+(total-((i+1)*a)).toFixed(2)+'</span><span class="to-inline-block height30 aligncenter output-cell output-cell-4">'+ratio_per_month.toFixed(2)+'</span></div>';//輸出每月詳情document.getElementById( "permonth" ).innerHTML = html;}//計算真實年利率totalRatio = b*(1+(cc-totalRatio)/totalRatio);//輸出各個數值document.getElementById( "list" ).innerHTML ='<div class="collect">每月需還本金:<p>'+a.toFixed(2)+'</p></div><div class="collect">每月實付利息:<p>'+aa.toFixed(2)+'</p></div><div class="collect">總還款金額:<p>'+c.toFixed(2)+'</p></div><div class="collect">總產生利息:<p>'+cc.toFixed(2)+'</p></div>';//輸出表面年利率及真實年利率document.getElementById( "real" ).innerHTML ='<div class="collect">表面年利率:'+(b*100).toFixed(2)+'%</div><div class="collect">真實年利率:'+(totalRatio*100).toFixed(2)+'%</div>';document.getElementById( "reset" ).classList.remove( "hidden" );}function reset(){document.getElementById( "output-table" ).classList.add( "hidden" );document.getElementById( "reset" ).classList.add( "hidden" );document.getElementById( "ratio" ).value = 0.66;document.getElementById( "total" ).value = 10000;document.getElementById( "number" ).value = 12;}</script></head><body class="aligncenter"><div class="table"><div id="count" class="width400 margincenter"><p><span class="label to-inline-block height30">總金額:</span><input class="numbers height30" type="text" id="total" name="total" value="10000" onfocus="hiddenValue('total')" onblur="displayValue('total')"></p><p><span class="label to-inline-block height30">月利率(%):</span><input class="numbers height30" type="text" id="ratio" name="ratio" value="0.66" onfocus="hiddenValue('ratio')" onblur="displayValue('ratio')"></p><p><span class="label to-inline-block height30">期數:</span><input class="numbers height30" type="text" id="number" name="number" value="12" onfocus="hiddenValue('number')" onblur="displayValue('number')"></p><p><input type="button" id="count-btn" name="count" value="計算" onClick="count()" class="btn"></p></div><div id="output-table" class="output-table width400 margincenter hidden"><p id="list" class="width400 output-rows"></p><p class="font0 header-list"><span class="to-inline-block height30 aligncenter output-cell output-cell-1">期數</span><span class="to-inline-block height30 aligncenter output-cell output-cell-2">還款前本金</span><span class="to-inline-block height30 aligncenter output-cell output-cell-3">還款后本金</span><span class="to-inline-block height30 aligncenter output-cell output-cell-4">應付利息</span></p><p id="permonth"></p><p id="real"class="width400 output-rows"></p><p><input type="button" id="reset" name="reset" value="重置" onClick="reset()" class="btn"></p></div></div><p class="height30 aligncenter">CopyRight &copy; 2019 由<a href="http://www.ixcrap.com">Art-Molec</a>制作</p></body> </html>

演示

信用卡分期真實利率計算器

?

總結

以上是生活随笔為你收集整理的JS信用卡真实利率计算器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。