Jason
Jason

Reputation: 3

JavaScript Math: How do I write this?

In Excel I have:

=(((SQRT(40))*($E$8/C16))^2)*1.1

Which is like:

(((SQRT(40)) * (7.695 / 0.200) ) ^2) *1.1;

I can't get it working in Javascript!

I have:

answer = (Math.exp(((Math.sqrt(40)) * (7.695 / 0.200))) *1.1);

I am getting something like: 5.265317066795887e+105

When I expect to get something like: 65168

Can anyone help see my error?

Upvotes: 0

Views: 183

Answers (1)

theomega
theomega

Reputation: 32031

Math.exp(x) is not x^2 but according to the docs e^x. You want to use Math.pow(x,y) (doc) which means x^y instead. Use this expression:

answer = Math.pow(Math.sqrt(40) * (7.695 / 0.200), 2)*1.1;

Upvotes: 12

Related Questions