I am needing to take the average of 5 numbers that will usually be between 800 and 1200 each. The numbers I am returning need to be whole numbers (906, not 906.42634...). Thanks for any help.
Printable View
I am needing to take the average of 5 numbers that will usually be between 800 and 1200 each. The numbers I am returning need to be whole numbers (906, not 906.42634...). Thanks for any help.
How about using Vb6's Round function?
If you do not have Vb6, you can use this code:Code:MsgBox Round(906.42634) 'returns 906
Code:Function Round(nValue As Double, nDigits As _
Integer) As Double
Round = Int(nValue * (10 ^ nDigits) + _
0.5) / (10 ^ nDigits)
End Function
Usage:
MsgBox Round(906.42634, 0) 'returns 906
MsgBox Round(906.42634, 2) 'returns 906.43
In VB I'm sure that would work. I just don't know how to make that work in ASP. I tried using the Round function as follows but it didn't work.
Thanks for any helpCode:round(intAht_avg = (int(aht1) + int(aht2) + int(aht3) + int(aht4) + int(aht5) + int(aht6) + int(aht7))/5)
The round() function is available in vbscript and works just like Matthew described...
Code:intAht_avg = round((round(aht1) + round(aht2) + round(aht3) + round(aht4) + round(aht5) + round(aht6) + round(aht7))/7))
'If you need an average, you will need to divide by 7 not 5 here)
'Or for a more acurate (but not totally accurate) average:
intAht_avg = round((aht1 + aht2 + aht3 + aht4 + aht5 + aht6 + aht7)/7)
I found that using Cint did exactly what I was looking for. Thank you though.
The people I would be doing these for are working 5 out of the 7 days, so dividing by 5 was the correct number. the others default to 0