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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Round currency 2

Status
Not open for further replies.

ashows

MIS
May 10, 2002
25
US
I am creating an Access XP database for oil well royalties. Each of the wells has 3-5 working interest investors, each with equal percent ownership of the royalties. When the royalty check is distributed, the payment amount does not always come out perfectly equal. For example, $821.06/3=$$273.6866666667. In this case, two of the investors would be paid $273.69 and one would be paid $273.68. How can I get the computer to (1) calculate the correct amounts and (2) randomly determine which investor gets the different amount?
 
Hi.

OK, I'm going to attempt to solve this.

Lets first look at the theory behind this.

The 821.06 that you speak of, lets give this a name, say, totval.

The 3 that you are dividing this value by, lets give that a name like, say, divisor.

OK, the answer that you are looking at is fairly straight forward math.

If I have the number 821.06 and divide that by 3, rounding off to 2 decimal values, I get 273.69.
I multiply this number by 3 giving me 821.07, which is 0.01 out of the desired value that we want.
So, I multiply 273.69 by (divisor - 1) /or 2/ giving 547.38.
I then take the 821.06 and remove 547.38 from it giving 273.68.

So, agreed that 2 people would get 273.69, and 1 person would get 273.68

OK, so in order to prove my hypothesis I am going to need somewhere to output my resultant data.

I therefore need you to create a new blank database. Create a textbox called txtTotVar. Create another called txtDivisor. Create another called txtResult. Create a button called "GO". Now, for the "GO" button we are going to write a sub which will take the value that you type into txtTotVar, divide it by the value in txtDivisor, and output the same hypothesis that I just explained into the textbox txtResult.

OK, so for the click button's click event :


Private Sub GO_Click()

'I am not going to incorporate error checking here as that would
'be outside the scope of this question

Me.txtResult = ""

'get the divided value
tmpDivVal = Format(CDbl(Me.txtTotVar), "##########.##")
tmpResultA = Format(tmpDivVal / Format((Me.txtDivisor), "######"), "##########.##")

For i = 1 To (CInt(Me.txtDivisor) - 1)

Me.txtResult = Me.txtResult & "Person Number " & i & " gets $" & tmpResultA & ". "

Next i

Me.txtResult = Me.txtResult & "Person Number " & Me.txtDivisor & " gets " & Format(tmpDivVal - (Format(tmpResultA * (CInt(Me.txtDivisor) - 1))), "##########.##")

End Sub


Hope this helps
Mr Big Dont be small. be BIG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top