Java Double Number Create toDouble(Object obj)

Here you can find the source of toDouble(Object obj)

Description

to Double

License

Open Source License

Declaration

public static double toDouble(Object obj) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double toDouble(Object obj) {
        return toDouble(obj, 0d);
    }//from   w  ww  . j  av a 2  s.  co  m

    public static double toDouble(Object obj, double defaultValue) {
        if (obj == null) {
            return defaultValue;
        }

        if (obj instanceof Number) {
            Number number = (Number) obj;
            return number.doubleValue();
        }
        String value = toString(obj);
        try {
            return Double.parseDouble(value);
        } catch (Exception e) {
        }
        return defaultValue;
    }

    public static String toString(Object value) {
        if (value == null) {
            return "";
        }
        return value.toString().trim();
    }
}

Related

  1. toDouble(Object obj)
  2. toDouble(Object obj)
  3. toDouble(Object obj)
  4. toDouble(Object obj)
  5. toDouble(Object obj)
  6. toDouble(Object obj)
  7. toDouble(Object object)
  8. toDouble(Object object, double defaultValue)
  9. toDouble(Object object, Double defaultValue)