Java Decimal Format toDecimalFromSexagesimalDegrees( final double sexagesimal)

Here you can find the source of toDecimalFromSexagesimalDegrees( final double sexagesimal)

Description

to Decimal From Sexagesimal Degrees

License

Apache License

Declaration

public static double toDecimalFromSexagesimalDegrees(
            final double sexagesimal) 

Method Source Code

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

import java.text.DecimalFormat;
import java.text.NumberFormat;

public class Main {
    public static double toDecimalFromSexagesimalDegrees(
            final double sexagesimal) {
        final String string = getFormat().format(sexagesimal);
        final int dotIndex = string.indexOf('.');

        final int degrees = Integer.parseInt(string.substring(0, dotIndex));
        final int minutes = Integer.parseInt(string.substring(dotIndex + 1,
                dotIndex + 3));//from  ww w .  j a v a  2  s . co  m
        final double seconds = Double.parseDouble(string.substring(
                dotIndex + 3, dotIndex + 5)
                + "."
                + string.substring(dotIndex + 5));
        double decimal;
        if (sexagesimal < 0) {
            decimal = degrees - minutes / 60.0 - seconds / 3600.0;
        } else {
            decimal = degrees + minutes / 60.0 + seconds / 3600.0;
        }
        return decimal;
    }

    private static NumberFormat getFormat() {
        return new DecimalFormat("#0.00000##########################");
    }
}

Related

  1. sanitizeDouble(String value)
  2. singleDecimalDigit(double d)
  3. string2Double(String s)
  4. strParaDouble(String s, double valorPadrao)
  5. to3DP(double number)
  6. toDecimals(double d, int nrDecs)
  7. toDouble(Object obj, String pattern)
  8. toDouble(String text)
  9. toDoubleObject(Object o)