I have an array of number [350000, 350000, 350000]
I have the following code:
function getNPV(rate, periods, Cashflow) {
var npv = 0;
for (var i = 0; i < Cashflow.length; i++) {
npv += Cashflow[i] / Math.pow(1 + rate, periods);
}
return npv;
}
Here, cashflow is our array, rate = 6% and period = 91days.
When I take :
npv = Cashflow[i] / Math.pow(1 + rate, periods);
The output is [348328,346664,344952] when 6% discount rate is applied to 350000 each time.
I am trying to take the sum of [348328,346664,344952] which is $1,039,944
But, it is giving me $1034856
as the result.
Trying the console, it's actually taking the sum of the 3rd value 3 times instead. [344952+344952+344952] for some reason.
Can someone please tell me how to fix this error. Any help is appreciated. Thank you.