Jakegarbo
Jakegarbo

Reputation: 1301

How to Translate excel PRODUCT formula

How to translate or restructure this =(1-PRODUCT(K5:K14)) excel formula to javascript code.

I did this code in my own understanding but result is not correct as i am expecting

exp_PRODUCT= [
  0.993758608,
  0.993847362,
  0.993934866,
  0.994021137,
  0.994106197,
  0.990118552,
  0.990226925,
  0.990334122,
  0.990440146,
  0.990545020
]

let result = 0.0;
  for(let prod of exp_PRODUCT){
    result = parseFloat(prod) + result;
  } 
 console.log('Total :' ,1-result )

expected answer is 7.XXXX%

Upvotes: 1

Views: 61

Answers (1)

Mr Smith
Mr Smith

Reputation: 3486

Try the following. Product is multiplication, not addition.

exp_PRODUCT= [
0.993758608,
0.993847362,
0.993934866,
0.994021137,
0.994106197,
0.990118552,
0.990226925,
0.990334122,
0.990440146,
0.990545020
]

result = 1.0;
  for(let prod of exp_PRODUCT){
    result = parseFloat(prod) * result;

  } 
 console.log('Total :' ,1 - result )

Upvotes: 1

Related Questions