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

后端 未结 4 714
说谎
说谎 2021-01-07 11:12

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

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-07 11:49

    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.

提交回复
热议问题