
function dms (lat, lon) {
  const λh = lat < 0 ? "S" : "N";
  const φh = lon < 0 ? "W" : "E";

  const λn = Math.abs(lat);
  const φn = Math.abs(lon);

  const λi = Math.trunc(λn);
  const φi = Math.trunc(φn);

  const λf = λn - λi;
  const φf = φn - φi;

  const λs = ((λf*3600)%60).toFixed(1);
  const φs = ((φf*3600)%60).toFixed(1);

  const λm = Math.trunc(λf*60);
  const φm = Math.trunc(φf*60);

  const λ =
    String(λi).padStart(2, "0") + "°" +
    String(λm).padStart(2, "0") + "'" +
    String(λs).padStart(4, "0") + '" ' +
    λh;

  const φ =
    String(φi).padStart(3, "0") + "°" +
    String(φm).padStart(2, "0") + "'" +
    String(φs).padStart(4, "0") + '" ' +
    φh;

  return λ+" "+φ;
}

module.exports = dms;
