0

In my excel sheet I'm using this formula

=10615.30152 *(1+$B$9-$B$10)^L4

here $B$9= 2.75% and $B$10 = .20% and L4 changes for each row from 0 to 30

In my javascript I'm trying to calculate value like this:

for(let i=0;i<31; i++){
 cashFlow = 10615.30152 * (1 + 2.75/100 - 0.20/100) ** i;
}

With each new row the amount mismatching is getting bigger.

1
  • How do you figure? I tested this in a Google Spreadsheet and compared to the script (modified to show output at each step), and the calculations are accurate to five digits (JS outputs 12 digits after the decimal).
    – sfdcfox
    Nov 12, 2021 at 0:26

1 Answer 1

1

I compared the output in a spreadsheet vs in JS, and come up with the following table:

Index Spreadsheet JS Output
0 10615.30152 10615.30152
1 10885.99171 10885.991708760002
2 11163.5845 11163.584497333384
3 11448.2559 11448.255902015384
4 11740.18643 11740.186427516777
5 12039.56118 12039.561181418458
6 12346.56999 12346.569991544628
7 12661.40753 12661.407526329016
8 12984.27342 12984.273418250408
9 13315.37239 13315.372390415794
10 13654.91439 13654.9143863714
11 14003.1147 14003.114703223871
12 14360.19413 14360.19412815608
13 14726.37908 14726.379078424063
14 15101.90174 15101.901744923878
15 15487.00024 15487.000239419434
16 15881.91875 15881.918745524632
17 16286.90767 16286.907673535512
18 16702.22382 16702.22381921067
19 17128.13053 17128.130526600544
20 17564.89786 17564.897855028856
21 18012.80275 18012.802750332095
22 18472.12922 18472.129220465562
23 18943.16852 18943.168515587437
24 19426.21931 19426.21931273492
25 19921.58791 19921.58790520966
26 20429.5884 20429.588396792507
27 20950.5429 20950.542900910717
28 21484.78174 21484.78174488394
29 22032.64368 22032.64367937849
30 22594.47609 22594.47609320264

I'm not sure what you're considering as descrepency, as the spreadsheet values are less accurate than the JS values by 7 digits past the decimal point, and all of them line up very closely to what the spreadsheet shows.

Perhaps you've made some error in your formula in the spreadsheet, or it may be a bug in Excel (I used Google Spreadsheets to perform this calculation).

1
  • apparently, my variable was returning 0
    – sfdc
    Nov 12, 2021 at 16:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .