Java Degree Convert to toDegrees(double degrees, int nDecimals, boolean longitude)

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

Description

to Degrees

License

Open Source License

Declaration

public final static String toDegrees(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 final static String toDegrees(double degrees, int nDecimals, boolean longitude) {
        NumberFormat degreesFormatter = NumberFormat.getInstance();
        degreesFormatter.setMinimumFractionDigits(nDecimals);
        degreesFormatter.setMaximumFractionDigits(nDecimals);
        degreesFormatter.setMinimumIntegerDigits(longitude ? 3 : 2);

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

        String degString = Integer.toString((int) Math.abs(Math.floor(degrees)));
        String zeroes = "00".substring(0, (longitude ? 3 : 2) - degString.length());
        degString = zeroes + degString;/*from   ww w  .j a v a 2  s  .  c o  m*/

        return degreesFormatter.format(degrees) + degreeSign + hemisphere;
    }
}

Related

  1. degreesToPercent(float n)
  2. degreesToRA(double val)
  3. degreesToSexigessimal(double ra, double dec)
  4. degreesToString(final double value, final char positiveChar, final char negativeChar)
  5. toDecimalDegrees(String picaValue)