Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rounding to 100% Maths Problem

Status
Not open for further replies.

kennedymr2

Programmer
May 23, 2001
594
AU
I am having (I think!) a maths problem in VB
When i run the following i get this result

1. % works out to 117.837121212
2. % should be 100.000% but works out to 100.9082259

Is my problem the way decimal points calculate in vb, OR
!!maybe! my maths formula is DUD!!!
=========================

Private Sub Command123_Click()

Dim test(6) As Double

test(0) = 22
test(1) = 3
test(2) = 8
test(3) = 0
test(4) = 32
test(5) = 2
test(6) = 12

Dim accum, accumx, accumc As Double
accum = 0

For ll = 0 To 6

If test(ll) > 0 Then
accumx = test(ll)
accum = accum + (100 / accumx + 1)
End If

Next ll

MsgBox (accum)


'Now reduce to 100%

For ll = 0 To 6
If test(ll) > 0 Then
test(ll) = test(ll) / 100 * accum
End If
Next ll

accum = 0

For ll = 0 To 6

If test(ll) > 0 Then
accumx = test(ll)
accum = accum + (100 / accumx + 1)
End If

Next ll

MsgBox (accum)



End Sub
 
Sorry, Forget the problem i had a +1 in the code which is in error. I put it in for some other reason and forgot to take it out.
@#@# Sorry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top