Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static double DoubleLonLatFromString(String string) {
        int pos = -1;
        double k = 1f / 60f;
        double result = 0;
        if (string.indexOf('.') != -1) {
            pos = string.indexOf('.');
        }
        if (string.indexOf(',') != -1) {
            pos = string.indexOf(',');
        }
        if (pos == -1) {
            //TODO
            if (string.length() >= 2) {
                result = result + Double.valueOf(string.substring(0, 2));
            }
            if (string.length() >= 4) {
                result = result + k * Double.valueOf(string.substring(2, 4));
            }
            if (string.length() >= 6) {
                result = result + k * k * Double.valueOf(string.substring(4, string.length()));
            }
        }
        //dd,dddddddddd
        //ddd.ddddddddd
        if (pos == 1 || pos == 2) {
            result = Double.valueOf(string);
        }
        //ddmm.mmmmmm
        //dddmm.mmmmmmmm
        if (pos == 5) {
            result = Double.valueOf(string.substring(0, 3))
                    + k * Double.valueOf(string.substring(3, string.length() - 1));
        }
        //dddmm.mmmmmmmm
        if (pos == 4) {
            result = Double.valueOf(string.substring(0, 2))
                    + k * Double.valueOf(string.substring(2, string.length()));
        }

        //ddmmss.ssssssssss
        if (pos == 6) {
            result = Double.valueOf(string.substring(0, 2)) + k * Double.valueOf(string.substring(2, 4))
                    + k * k * Double.valueOf(string.substring(4, string.length()));
        }
        //dddmmss.ssssssssss
        if (pos == 7) {
            result = Double.valueOf(string.substring(0, 3)) + k * Double.valueOf(string.substring(3, 5))
                    + k * k * Double.valueOf(string.substring(5, string.length()));
        }
        return result;
    }
}