我正在尝试用 javascript 计算复利。我相信我拥有我需要的所有值(value)观,而且我也有公式。我正在努力解决如何将公式的 ^
部分转换为 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));
作为示例,我将质数设置为 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)
关于javascript - 如何使用 Math.pow() 来求解复利?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34207470/