Skip to content

Instantly share code, notes, and snippets.

@gzuri
Created July 19, 2012 12:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gzuri/3143419 to your computer and use it in GitHub Desktop.
Save gzuri/3143419 to your computer and use it in GitHub Desktop.
C# GPS location format converter
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