I'm trying to see if two given numbers, for example 1.134 and 1.135 have the same decimals. So far everything works correctly, but when working with number with a large number of decimals I have a problem: I get the following error for the following input 0.841666666666667, 0.841468253968254:
Unhandled Exception:
System.OverflowException: Arithmetic operation resulted in an overflow.
This is my code
Function TrueOrFalse(ByVal x As Double, ByVal y As Double, ByVal n as Integer) As Boolean
For i As Integer = 1 To n+1
If CInt(x) <> CInt(y) Then
Return False
End If
x *= 10
y *= 10
Next
Return True
End Function
I understand that it's because the Int type cannot contains that much digits, and when changing CInt to CLng everything works perfectly. Problem: I cannot use CLng. Is there any alternatives ? Thanks!