P2P金融利息和复利算法
// 计算投资金额amt,投资几个月mons所有收益算法 function calcProfit(amt, mons) { var totalRate = 0; var yearDays = 365; var monthDays = yearDays / 12; for (var i = 1; i <= mons; i++) { var num = i < 6 ? i : 6; var rate = (0.045 + ((num - 1) * 0.005)) * 100 / 100; totalRate += rate * 10e10 / 10e10; } return amt * (totalRate / yearDays * monthDays); }
// 计算复利利息 function calcFuLiProfit(amt, mons) { var yearDays = 365; var a = function(rate) { return rate / yearDays * amt; }; var b = function(rate, days) { if (days > 1) { return a(rate) + b(rate, days - 1); } else { return a(rate); } }; var totalAmt = 0; var monthDays = yearDays / 12; for (var i = 1; i <= mons; i++) { var num = i < 6 ? i : 6; var rate = (0.045 + ((num - 1) * 0.005)) * 100 / 100; totalAmt += b(rate, monthDays); } return totalAmt; }
注:本算法仅供参考,算法涉及数值请以实际计算规则进行修改。
相关推荐
yslg0 2020-08-12
banlanxiaoxue 2020-06-09
huimor 2020-06-09
布衣 2020-05-26
banlanxiaoxue 2020-05-26
guotiaotiao 2020-06-06
博主回家睡觉了 2020-05-08
羽化成蝶 2020-05-08
xxzz 2020-04-23
jessis00 2020-03-28
辛佳雨 2020-03-06
wangxuekuan 2020-03-03
SJCHEN 2020-02-22
Norsaa 2020-02-21
pxy 2020-02-18
banlanxiaoxue 2020-02-12
hiarxiaoliang 2020-01-30
lookat 2020-01-18
我心向佛善哉善哉 2020-01-17