JavaScript中计算复利
复利公式
复利使用以下公式计算-
CI = P*(1 + R/n) (nt) – P
这里,
P是本金。
R是年利率。
t是金钱被投资或借入的时间。
n是每单位t复利的次数,例如,如果每月复利一次,t以年为单位,则n的值为12。如果每季度复利一次,t以年为单位,则n的值将是4。
我们需要编写一个JavaScript函数,该函数接受本金,利率,时间和数字n并计算复利。
示例
让我们为该函数编写代码-
const principal = 2000;
const time = 5;
const rate = .08;
const n = 12;
const compoundInterest = (p, t, r, n) => {
const amount = p * (Math.pow((1 + (r / n)), (n * t)));
const interest = amount - p;
return interest;
};
console.log(compoundInterest(principal, time, rate, n));输出结果
控制台中的输出:-
979.6914166032097
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语