Justin Erswell
Justin Erswell

Reputation: 708

Excel formulas to Javascript Math

I have a number of formulas which are in Excel form and I know I have asked for help on these kind of things before but I have three more formulas that I cannot work out how to express in javascript.

the variables are

var J17 = 6.50;
var C19 = 5;
var C20 = 6;
var C22 = 0.5;
var E26 = 0.5; 
var F26 = 0.5;

Formula 1:

=1/(1+J$17*C$22*0.01)^((E26/C$22)) - Should return 0.968523002

Formula 2:

=IF(F26=C$19,100,0) - Should return 0.00

Formula 3:

=IF(E26>C$19,0,C$20*C$22) - Should return 3.00

Thats is my main problem is with Formula 1, I know that the ^ is expressed using Math.pow but I cannot work out where it should go in the javascript expression. I have had a try at this:

var calcValue = (1 /  Math.pow(1 + J17 * C22 * 0.01), (E26/C22) );

But it returns infinity

Upvotes: 0

Views: 1094

Answers (1)

Madbreaks
Madbreaks

Reputation: 19539

You've got a paren out of place:

var calcValue = (1 /  Math.pow(1 + J17 * C22 * 0.01), (E26/C22)
                ^

Try:

var calcValue = 1 /  Math.pow((1 + J17 * C22 * 0.01), (E26/C22))
                             ^

For what it's worth, your original formula has a useless extra set of parens too: ((E26/C$22))

EDIT Updated + 0.01 to * 0.01, as your original post had that same error. ;)

Upvotes: 2

Related Questions