This should be so simple. I need a function that when passed 2 doubles and the second is divided into the first, returns the remainder (including decimal places).
I have written this. It works most of the time:
VB Code:
Public Function GetRemainder(dNumber1 As Double, dNumber2 As Double) As Double 'Returns the remainder after diving dNumber1 by dNumber2 Dim dDiv As Double Dim iInt As Integer Dim dResult As Double dDiv = dNumber1 / dNumber2 iInt = Int(dDiv) dResult = dDiv - iInt GetRemainder = dResult * dNumber2 End Function
However, when I passed dNumber1 = 1.2 and dNumber2 = 0.4, I would expect it to return 0 but it returns 0.4 because
Int(1.2 / 0.4) returns 2 not 3. Why??
Is there an intrinsic VB function that does this operation or does someone have a function that does work?




Reply With Quote