Java Regex Double Validate parseDouble(Object object)

Here you can find the source of parseDouble(Object object)

Description

parse Double

License

LGPL

Declaration

public static double parseDouble(Object object) 

Method Source Code

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

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static final String regexDouble = "^-?\\d+(\\.\\d)*";

    public static double parseDouble(Object object) {
        if (null == object)
            return 0.0;
        String str = object.toString();
        if ("".equals(str))
            return 0.0;
        str = getFirstMatcher(regexDouble, str);
        return Double.parseDouble(str);
    }/* w w  w.ja  v a  2s .co m*/

    public static String getFirstMatcher(String regex, String str) {
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        while (matcher.find()) {
            return matcher.group();
        }
        return null;
    }
}

Related

  1. parseDouble(final String text)
  2. parseDouble(Object value, Double replace)
  3. parseDouble(String myString)
  4. parseDouble(String s)
  5. parseDouble(String str)