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:
  1. Public Function GetRemainder(dNumber1 As Double, dNumber2 As Double) As Double
  2. 'Returns the remainder after diving dNumber1 by dNumber2
  3. Dim dDiv As Double
  4. Dim iInt As Integer
  5. Dim dResult As Double
  6.  
  7. dDiv = dNumber1 / dNumber2
  8.  
  9. iInt = Int(dDiv)
  10.  
  11. dResult = dDiv - iInt
  12.  
  13. GetRemainder = dResult * dNumber2
  14.  
  15. 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?