/** * Returns the degrees or minutes or seconds (depending on parameter what) formatted as a string * To determine the degrees, we need to calculate the minutes (and seconds) just in case rounding * errors propagate. Equally we need to know the seconds to determine the minutes value. * * @param deg The coordinate in degrees * @param what 0=deg, 1=min, 2=sec * @param format DD,CW,DMM,DMS * @return */ private String getDMS(double deg, int what, int format) { deg = Math.abs(deg); long iDeg = (int) deg; double tmpMin, tmpSec; tmpMin = (deg - iDeg) * 60.0; switch (format) { case DD: return ""; case CW: case DMM: // Need to check if minutes would round up to 60 if (java.lang.Math.round(tmpMin * 1000.0) == 60000) { tmpMin = 0; iDeg++; } switch (what) { case 0: return MyLocale.formatLong(iDeg, "00"); case 1: return MyLocale.formatDouble(tmpMin, "00.000").replace(',', '.'); case 2: return ""; } case DMS: tmpSec = (tmpMin - (int) tmpMin) * 60.0; tmpMin = (int) tmpMin; // Check if seconds round up to 60 if (java.lang.Math.round(tmpSec * 10.0) == 600) { tmpSec = 0; tmpMin = tmpMin + 1.0; } // Check if minutes round up to 60 if (java.lang.Math.round(tmpMin) == 60) { tmpMin = 0; iDeg++; } switch (what) { case 0: return MyLocale.formatLong(iDeg, "00"); case 1: return MyLocale.formatDouble(tmpMin, "00"); case 2: return MyLocale.formatDouble(tmpSec, "00.0").replace(',', '.'); } } return ""; // Dummy to keep compiler happy }