PDA

Click to See Complete Forum and Search --> : Whole numbers


artsapimp
Oct 3rd, 2000, 12:34 PM
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.

Oct 3rd, 2000, 01:44 PM
How about using Vb6's Round function?

MsgBox Round(906.42634) 'returns 906

If you do not have Vb6, you can use this 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

artsapimp
Oct 3rd, 2000, 02:06 PM
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.


round(intAht_avg = (int(aht1) + int(aht2) + int(aht3) + int(aht4) + int(aht5) + int(aht6) + int(aht7))/5)


Thanks for any help

monte96
Oct 3rd, 2000, 03:57 PM
The round() function is available in vbscript and works just like Matthew described...


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)

artsapimp
Oct 3rd, 2000, 04:29 PM
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