Created
July 19, 2012 12:09
-
-
Save gzuri/3143419 to your computer and use it in GitHub Desktop.
C# GPS location format converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void ConvertDecimalToSexagesimal(decimal input, out int deg, out int min, out int sec) | |
{ | |
if (input < 0) | |
{ | |
input = -input; | |
} | |
deg = (int)input; | |
min = (int)Math.Round((input - deg) * 60); | |
sec = (int)Math.Round((((input - deg) - (decimal)min / 60) * 3600), 0); | |
if (sec < 0) | |
sec += 60; | |
if (sec == 60) | |
{ | |
min++; | |
sec = 0; | |
} | |
if (min == 60) | |
{ | |
deg++; | |
min = 0; | |
} | |
} | |
public static decimal ConvertSexagesimalToDecimal(int deg, int min, int sec) | |
{ | |
return (decimal)deg + (decimal)min / 60 + (decimal)sec / 3600; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment