如何使用 Math.pow() 来计算复利?

How can I use Math.pow() to solve for compounding interest?

我正在尝试用 javascript 计算复利。我相信我拥有我需要的所有价值观,而且我也有公式。我正在为如何将公式的 ^ 部分转换为 Math.pow() 而苦恼。很明显,我不知道如何在下面正确使用它...

公式如下:

A = P(1 + r/n)^nt

n = 365 – assuming daily compounding
P = Principal
r = interest rate
t = years
A = accrued amount: principal + interest

这是我目前的情况:

totalInterest = (principal) * (1 + loanInterestRate / 365)(Math.pow(daysOfInterest, yearsOfInterest));

例如,我将 prime 设置为 3.25%,付款到期日为 12/30/2016。使用值看起来像这样:

(50000) * (1 + 0.0325 / 386) Math.pow(386, 1);

// 386 is the number of days from today till 12/30/2016. 
// 1 is: 1 year from today till 12/30/2016

显然这行不通。我不确定如何正确实施数学,任何建议都会有所帮助。

谢谢!

编辑

再次感谢您的回答。这正是我需要的推动力 - 显然我不会数学。

我也想用我的完整答案更新这个...

totalInterest = Math.round(((principal) * Math.pow(1 + loanInterestRate / 365, daysOfInterest * 1)) - principal);
loanNetCost = (principal) + (loanTotalInterest);

alert('You will owe this much money: + loanNetCost');

您需要将其更改为:

(50000) * Math.pow(1 + 0.0325 / 386, 386 * 1)
A = P(1 + r/n)^nt

n = 365 – assuming daily compounding
P = Principal
r = interest rate
t = years
A = accrued amount: principal + interest

A = P * Math.pow(1 + r/n, nt);
Math.pow(daysOfInterest, yearsOfInterest)

表示n^t所以Math.pow(386, 1)表示386的1次方。

您需要将所有表达式 (1 + r/n) 计算为 nt 次方。

给予

(50000) * Math.pow(1 + 0.0325 / 386, 386 * 1)