Degrees, Minutes, Seconds to Decimal Degrees
I have been asking around to see if there is an existing class method in C# to do this and it appears not, so I worked out my own methods if anyone is interested or needs them.// angle or bearing in degrees, minutes and secondsdouble angle = 45.2413;//degrees, minutes and...
I have been asking around to see if there is an existing class method in C# to do this and it appears not, so I worked out my own methods if anyone is interested or needs them.
// angle or bearing in degrees, minutes and seconds double angle = 45.2413; //degrees, minutes and seconds double degminsec = angle; // decimal seconds double decsec = (degminsec * 100 - Math.Truncate(degminsec*100)) / .6; //degrees and minutes double degmin = (Math.Truncate(degminsec * 100) + decsec) / 100; //degrees double deg = Math.Truncate(degmin); //decimal degrees double decdeg = deg + (degmin - deg) / .6;And this is to go from DecDeg to DMS:
// angle in decimal degrees double angle = 45.4036; //decimal degrees double decdeg = angle; //integer is minutes and the decimal is decimal seconds double minsec = (decdeg - Math.Truncate(decdeg)) * 60; //seconds double sec = (minsec - Math.Truncate(minsec)) * 60; //degrees, miutes and seconds double degminsec = (Math.Truncate(sec) / 10000) + (Math.Truncate(minsec) / 100) + Math.Truncate(decdeg);