【发布时间】:2017-10-17 02:12:41
【问题描述】:
编写一个名为“computeCompoundInterest”的函数。
给定本金、利率、复利频率和 时间(年),“computeCompoundInterest”返回金额 产生复利。
var output = computeCompoundInterest(1500, .043, 4, 6);
console.log(output); // --> 438.8368221341061
参考: https://en.wikipedia.org/wiki/Compound_interest#Calculation_of_compound_interest 这显示了用于计算产生的总复利的公式。
问题是我正在尝试使用此公式但无法正确使用
function computeCompoundInterest(p, i, compoundingFrequency, timeInYears) {
p = p * (1 + (i/4)))^(compoundingFrequency*timeInYears)
}
我尝试逐步完成每个计算,看起来一旦我到达:
p = 1500 * (1 + 0.043/4)^ 4 x 6 //compoundingFrequency = 4 and timeInYears = 6
我做错了什么。当你(1 + (i/4)))^(compoundingFrequency*timeInYears) 时,这个website 似乎得到一个十进制数
【问题讨论】:
-
你试过 Math.pow(x, y) 吗?
-
^ 是按位异或不是幂。
-
^是 bitwise XOR - 不是pow。你可能想要p = 1500 * Math.pow((1 + 0.043/4), 4) * 6
标签: javascript