Java Degree Convert to degreesToDecimal(String input)

Here you can find the source of degreesToDecimal(String input)

Description

degrees To Decimal

License

LGPL

Declaration

public static double degreesToDecimal(String input) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    public static double degreesToDecimal(String input) {
        char direction = input.charAt(0);
        int degrees;
        int minutes;
        int seconds;
        if (direction == 'E' || direction == 'W') {
            degrees = Integer.parseInt(input.substring(1, 4));
            minutes = Integer.parseInt(input.substring(4, 6));
            seconds = Integer.parseInt(input.substring(6));
        } else {/*from ww w. j  a  v a2 s  .c o m*/
            degrees = Integer.parseInt(input.substring(1, 3));
            minutes = Integer.parseInt(input.substring(3, 5));
            seconds = Integer.parseInt(input.substring(5));
        }

        double decimal = degrees + (float) minutes / 60 + (float) seconds / 3600;

        if (direction == 'W' || direction == 'S') {
            decimal *= -1;
        }
        return decimal;
    }
}

Related

  1. degrees(double d)
  2. degrees2Dist(double degrees, double radius)
  3. degreesDiff(double a1, double a2)
  4. degreeSin(double angle)
  5. degreesMinSecToDegrees(String position)
  6. degreesToMetres(double degrees)
  7. degreesToPercent(float n)
  8. degreesToRA(double val)
  9. degreesToSexigessimal(double ra, double dec)