Skip to content

Instantly share code, notes, and snippets.

@adamgavlak
Created June 20, 2017 16:49
Show Gist options
  • Save adamgavlak/75114015dd75eb9b5fdcfc2aa436971f to your computer and use it in GitHub Desktop.
Save adamgavlak/75114015dd75eb9b5fdcfc2aa436971f to your computer and use it in GitHub Desktop.
function deg_to_dms(deg) {
var d = Math.floor (deg);
var minfloat = (deg-d)*60;
var m = Math.floor(minfloat);
var secfloat = (minfloat-m)*60;
var s = Math.round(secfloat);
// After rounding, the seconds might become 60. These two
// if-tests are not necessary if no rounding is done.
if (s==60) {
m++;
s=0;
}
if (m==60) {
d++;
m=0;
}
return (d + "°" + m + "\'" + s + "\"");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment