Java Double Number Create toDouble(Object value)

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

Description

Convert an Object to a Double.

License

Apache License

Declaration

public static Double toDouble(Object value) 

Method Source Code

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

public class Main {
    /**// ww  w  .  j  av a 2  s. com
     * Convert an Object to a Double.
     */
    public static Double toDouble(Object value) {
        if (value == null)
            return null;
        if (value instanceof Double)
            return (Double) value;
        if (value instanceof String) {
            if ("".equals((String) value))
                return null;
            return new Double((String) value);
        }
        if (value instanceof Number)
            return new Double(((Number) value).doubleValue());

        return new Double(value.toString());
    }

    /**
     * Convert an Object to a double, or 0 if it is null.
     */
    public static double doubleValue(Object value) {
        if (value == null)
            return 0.0;
        return toDouble(value).doubleValue();
    }
}

Related

  1. toDouble(Object val)
  2. toDouble(Object val)
  3. toDouble(Object value)
  4. toDouble(Object value)
  5. toDouble(Object value)
  6. toDouble(Object value)
  7. toDouble(Object value, double nullValue)
  8. toDouble(Object x)
  9. toDouble(short[] arr)