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
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便