如何使用'^';在JavaScript的这个函数中?

如何使用'^';在JavaScript的这个函数中?,javascript,Javascript,编写一个名为“computeCompoundInterest”的函数 给定本金、利率、复利频率和 时间(以年为单位),“computeCompoundInterest”返回 产生复利 参考: 这显示了用于计算产生的总复利的公式 问题是,我试图使用这个公式,但无法正确使用 function computeCompoundInterest(p, i, compoundingFrequency, timeInYears) { p = p * (1 + (i/4)))^(compoundingFr

编写一个名为“computeCompoundInterest”的函数

给定本金、利率、复利频率和 时间(以年为单位),“computeCompoundInterest”返回 产生复利

参考: 这显示了用于计算产生的总复利的公式

问题是,我试图使用这个公式,但无法正确使用

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

我做错了什么事。当您使用运算符时,这似乎会得到一个十进制数


对于指数,您应该使用函数(如
Math.pow(2,3)==8
)或(如
2**3==8

^
运算符是


对于指数,您应该使用函数(如
Math.pow(2,3)==8
)或(如
2**3==8

您尝试过数学吗。pow(x,y)?^是按位异或而不是幂。
^
是-不是
pow
。你可能想要
p=1500*Math.pow((1+0.043/4),4)*6
你试过数学了吗。pow(x,y)?^是按位异或而不是幂。
^
是-不是
pow
。您可能需要
p=1500*Math.pow((1+0.043/4),4)*6
p = 1500 * (1 + 0.043/4)^ 4 x 6 //compoundingFrequency = 4 and timeInYears = 6