I'm trying to replicate a formula from an Excel worksheet onto an ASP page, but having copied the formula over I'm getting different results (in fact an error because the ASP ends up trying to square root a negative number).
Surely Excel handles operator precedence the same as classic ASP?
The formula I'm trying to replicate is a simple "T-Test" (to report on statistical significance - I didn't create the formula) and works correctly in Excel. In Excel, the cells look like
A2 = 1098
B2 = 183
A4 = 20.4
B4 = 17.49
And cell E4 contains this formula:
=(A4-B4)/SQRT(((($A$2*A4)+($B$2*B4))/($A$2+$B$2))*
(1-((($A$2*A4)+($B$2*B4))/($A$2+$B$2)))*((1/$A$2)+(1/$B$2)))
So, I simply copy/pasted that formula into classic ASP, removed all the $ and changed SQRT to SQR, declared 4 variables A2, B2, A4, B4. That returns an error (invalid procedure call).
If I remove the first part of the formula - (A4-B4)/SQRT - in ASP the code returns -2.41868099141296, yet in Excel it's returning 0.001019435.
I have tried and tried calculating parts of the formula separately first, and then putting it back together ready to do the SQRT but keep facing the same thing.
Is this just a silly mistake? At one point I was looking into square roots of negative numbers until I tried =SQRT(-9) in Excel
ASP Code I'm using is (I've inserted a line break on the first and last line):
A2 = cdbl(1098.0)
A4 = cdbl(20.4)
B2 = cdbl(183.0)
B4 =cdbl(17.49)
' Remove all the $, and (A4-B4)/SQRT part
response.write "<p>Result: " & ((((A2*A4)+(B2*B4))/(A2+B2))*(1-(((A2*A4)+(B2*B4))
/(A2+B2)))*((1/A2)+(1/B2))) & "</p>"`