Search code examples
c#coordinates

Convert decimal coordinates to Degrees, Minutes & Seconds by c#


Has anyone know simple short code to convert this without use additional libraries ?


Solution

  • Like this:

    double coord = 59.345235;
    int sec = (int)Math.Round(coord * 3600);
    int deg = sec / 3600;
    sec = Math.Abs(sec % 3600);
    int min = sec / 60;
    sec %= 60;
    

    Edit: Added an Abs call so that it works for negative angles also.