Java Minute Calculate toDegreesMinutes(double degrees, int nDecimals, boolean longitude)

Here you can find the source of toDegreesMinutes(double degrees, int nDecimals, boolean longitude)

Description

to Degrees Minutes

License

Open Source License

Declaration

public final static String toDegreesMinutes(double degrees, int nDecimals, boolean longitude) 

Method Source Code


//package com.java2s;
import java.text.NumberFormat;

public class Main {
    public static final String degreeSign = "\u00b0";
    public static final String minuteSign = "'";

    public final static String toDegreesMinutes(double degrees, int nDecimals, boolean longitude) {
        double[] dms = toDegreesMinutes(degrees);
        int deg = (int) dms[0];
        double min = dms[1];

        NumberFormat minutesFormatter = NumberFormat.getInstance();
        minutesFormatter.setMinimumFractionDigits(nDecimals);
        minutesFormatter.setMaximumFractionDigits(nDecimals);
        minutesFormatter.setMinimumIntegerDigits(2);

        String hemisphere = longitude ? (degrees >= 0.0 ? "E" : "W") : (degrees >= 0.0 ? "N" : "S");

        String degString = Integer.toString(Math.abs(deg));
        String zeroes = "00".substring(0, (longitude ? 3 : 2) - degString.length());
        degString = zeroes + degString;//from   w  ww .j  av a2s.c o m

        return degString + degreeSign + minutesFormatter.format(min) + minuteSign + hemisphere;
    }

    public final static double[] toDegreesMinutes(double degrees) {
        double sign = (degrees >= 0.0) ? 1.0 : -1.0;
        degrees = Math.abs(degrees);
        double[] dms = new double[2];
        dms[0] = Math.floor(degrees);
        double minutes = (degrees - dms[0]) * 60.0;
        dms[1] = minutes;
        dms[0] *= sign;
        return dms;
    }
}

Related

  1. minutesToHylaTime(int mins)
  2. plusMinute(Date date, int minutes)
  3. plusMinute(int minute)
  4. setMinutes(Date date, int amount)
  5. shiftTime(Object o, int minutes)
  6. toMinutes(Date fecha)
  7. toMinuteString(long time)