I am attempting to calculate the average of four percentage values, Each value has an associated integer, representing the number of times an action happened, with the percentage indicating success/failure.
To get the average mathematically I use the following (p = % value, i = integer):
((p1i1)+(p2i2)+(p3i3)+(p4i4))/(i1+i2+i3+i4)
The p and i values are retrieved from text fields in a NotesDocument using the GetFirstItem method. My problem occurs when multiplying the p and i values using the LS below:
For x = 1 To 4 'Cycle through report weeks
incr = x-1
week%=wk%-incr
id% = 13-x
If week% <=0 Then
week% = 52-incr
yr% = yr%-1
End If
For y = 1 To 4 'Cycle through data source weeks
src% = id%-(y+3)
Set cnt = doc.GetFirstItem("dctCount_"+Cstr(src%))
Set sat = doc.GetFirstItem("dctSat_"+Cstr(src%))
dcttotal(y) = cnt.Values(0)*sat.Values(0)
dctcount(y) = cnt.Values(0)
Next
Call doc.ReplaceItemValue("dctCount_"+Cstr(id%), dctcount(1)+dctcount(2)+dctcount(3)+dctcount(4))
Call doc.ReplaceItemValue("dctSat_"+Cstr(id%), (dcttotal(1)+dcttotal(2)+dcttotal(3)+dcttotal(4))/(dctcount(1)+dctcount(2)+dctcount(3)+dctcount(4)))
Next
Example, p1 = 0.9857, i1 = 67. Expected return value is 66.0419 of type double. Actual return value is 66
The debugger shows that sat.Values(0) is of type double and cnt.Values(0) is of type integer. My understanding was that multiplying a double by an integer would return a double.
Any suggestions? All are welcome as I’m obviously far from expert.
Thanks, Dave