Degrees, minutes and 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 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 back the other way:
// 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);
-
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 back the other way:
// 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);
-
You will find it under articles menu on the top Post Tip & Trick[^]
Tarakeshwar Reddy There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi
-
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 back the other way:
// 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);
The only problem with these conversions is that you will get incorrect answers. Try running a few tests to see what happens when converting between decimal values and floating point.
txtspeak is the realm of 9 year old children, not developers. Christian Graus
-
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 back the other way:
// 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);
How about just doing something like
deg + min / 60 + sec / 3600
Tarakeshwar Reddy There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi
modified on Saturday, March 27, 2010 3:49 PM
-
How about just doing something like
deg + min / 60 + sec / 3600
Tarakeshwar Reddy There are two kinds of people, those who do the work and those who take the credit. Try to be in the first group; there is less competition there. - Indira Gandhi
modified on Saturday, March 27, 2010 3:49 PM