Question : Access 2003:  Math question....Calculating a percentage

Hi EE,

I got help last year from EE in how to calcuate percentages.

A student can have one of the following grades in a course:
------------------------------------------------------------------
H - honors
HP - high pass
P - pass

Using a cross tab query, calculated (number of student) totals for each grade for a course
for ex:

 course                 H       HP       P
=============================
MEDI 1107             26     41      102      <-- break down of how many students scored a particular grade

What the snippet below does is convert the total of students below to percentages.
            26+41+102 = 169

            26/169  * 100 = 15.38
            41/169  * 100 =  24.26
           102/169  * 100 =  60.35

      Notice how the decimals portion is less than .50,
              so the results of the calc are:
                         15%
                          24%
                          60%
              that totals 99%

         Is there any way to get the percentages to total 100%  or is this to be expected in math?

tx for your thoughts and ideas, sandra



lngHCount = CLng(Nz(Me.txtHCount, 0))
lngHPCount = CLng(Nz(Me.txtHPcount, 0))
lngPCount = CLng(Nz(Me.txtPcount, 0))


lngTotal = lngHCount + lngHPCount + lngPCount

If lngTotal > 0 Then
    lngHpct = (lngHCount / lngTotal) * 100
Else
    lngHpct = 0
End If

If lngTotal > 0 Then
   lngHPpct = (lngHPCount / lngTotal) * 100
Else
   lngHPpct = 0
End If

If lngTotal > 0 Then
   lngPpct = (lngPCount / lngTotal) * 100
Else
   lngPpct = 0
End If


Me.txtHpct = lngHpct
Me.txtHPpct = lngHPpct
Me.txtPpct = lngPpct

Answer : Access 2003:  Math question....Calculating a percentage

I think the only opportunity to get 100% is add this 1 to the value with maximal decimal part. In your example it will be 15.38. Change it to 16 and you will have minimal deviation from reality.
Random Solutions  
 
programming4us programming4us