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

Remainders When Dividing?

Status
Not open for further replies.

Dannybe2

Programmer
Jan 31, 2001
136
GB
How do I divide a number by another and create a remainder:

Eg.
1523 / 60 = 25.3833333
1523 / 60 = 25 R23
 
Not sure if there's something more efficient...

You could use:

Dim sglRMNDR as single

sglRMNDR = (n1 / n2) - (n1 \ n2)

The second operator (\)is the Integer Division operator.
 
If there is no function available you could create your own


Example

Sub Button1_Click()
MsgBox GetRemainder(23, 5)
End Sub


Function GetRemainder(Num1 As Integer, Num2 As Integer) As Integer
MyVal = Num1 \ Num2
GetRemainder = Num1 - (MyVal * Num2)
End Function
 
1523 MOD 60 --------------
A little knowledge is a dangerous thing.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top