0

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

5
  • Should that be * 0.01? Commented Dec 4, 2014 at 22:05
  • Your right apologies will update Commented Dec 4, 2014 at 22:06
  • 1
    Your IF statements can be replaced with the format someCondition? valueiftrue : valueiffalse. So for the first one: F26 === C19? 100 : 0 Commented Dec 4, 2014 at 22:11
  • @MattBurland what would be the statement for this =IF(E26>C$19,0,E26) Commented Dec 4, 2014 at 22:33
  • Well, E26>C19 would be your condition, 0 would be your valueiftrue and E26 would be your value if false. So just plug them in. Commented Dec 5, 2014 at 2:11

1 Answer 1

2

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. ;)

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks that is producing a result (jsfiddle.net/9pgrw20f) but not the expected
Doesn't give the right answer unless you replace the +0.01 with *0.01
Also, you only actually need 1 / Math.pow(1 + J17 * C22 * 0.01, E26/C22 ); Those inner brackets aren't doing anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.