The first function is using a totally wrong formula. Whereas the second one, the function is expecting an integer minutes, or in other words, converts the decimal minutes to integer.
Both functions being called with: DMS_To_DD(51, 4, 212) DMS_To_DD(0, 12, 905)
Also your understanding of coordinates value representation is wrong. N51°4.212' is not equal to 51 degrees, 4 minutes and 212 seconds. Same goes with E0°12.905' <> 0 degrees, 12 minutes and 905 seconds.
UPDATES
Sorry, the previous function only work for +ve degrees. I have changed the formula to take care of NSWE of DMS value properly at the cost of an extra parameter nswe
to the function to determine sign of the returned decimal degrees. Try this:
Private Function DMS_To_DD(nswe As String, ByVal deg As UInteger, ByVal min As Double, ByVal sec As Double) As Double
' throw exception if min and/or sec are negative values
If min < 0 Or sec < 0 Then
Throw New ArgumentOutOfRangeException("min and/or sec", "Argument must be a positive value.")
End If
Dim sign As Integer
' nswe checking below only considers 's' or 'w' value
' in order to determine -ve degrees.
' 'n', 'e' or any invalid string will be default to +ve degrees.
Select Case nswe.ToUpper
Case "S", "W" : sign = -1
Case Else : sign = 1
End Select
Return sign * (deg + (min * 60 + sec) / 3600)
End Function
E.g:
To convert N54° 6.279':
DMS_To_DD("N", 54, 6.279, 0) ' returns 54.10465
To convert W4° 44.362':
DMS_To_DD("W", 4, 44.362, 0) ' returns -4.73936666666667
Hope this helps.