Java Double Number Create toDouble(Object ob, Double defaultDouble)

Here you can find the source of toDouble(Object ob, Double defaultDouble)

Description

to Double

License

Open Source License

Declaration

public static Double toDouble(Object ob, Double defaultDouble) 

Method Source Code

//package com.java2s;

public class Main {

    public static Double toDouble(Object ob, Double defaultDouble) {

        if (ob == null) {
            return defaultDouble;
        }//ww  w  . j a va  2 s  .  c  o m

        if (ob instanceof Integer) {
            return ((Integer) ob).doubleValue();
        } else if (ob instanceof Float) {
            return ((Float) ob).doubleValue();
        } else if (ob instanceof Double) {
            return ((Double) ob).doubleValue();
        } else if (ob instanceof Byte) {
            return ((Byte) ob).doubleValue();
        } else {
            try {
                return new Double(ob.toString());
            } catch (Exception e) {
                return defaultDouble;
            }
        }
    }

    public static Double toDouble(Object ob) {
        return toDouble(ob, 0d);
    }
}

Related

  1. toDouble(Object o)
  2. toDouble(Object o)
  3. toDouble(Object o)
  4. toDouble(Object o)
  5. toDouble(Object o)
  6. toDouble(Object obj)
  7. toDouble(Object obj)
  8. toDouble(Object obj)
  9. toDouble(Object obj)