public static double convertObjectToDouble(Object obj) {
	if (obj.getClass().toString().contains("Double")) {
		return (Double) obj;
	}
	if (obj.getClass().toString().contains("String")) {
		return convertStringToDouble((String) obj);
	}
	if (obj.getClass().toString().contains("Integer")) {
		return (Integer) obj;
	}
	Ts.printErr("error on converting to double");
	//----- it never be reached
	return -1;
}
 
public static double convertStringToDouble(String str) {
	return Double.parseDouble(str);
}
 
public static void printErr(String str) {
	System.out.println("---> error : " + str);
	System.exit(-1);
}


Back to JavaHowTo

Alumni Liaison

Ph.D. 2007, working on developing cool imaging technologies for digital cameras, camera phones, and video surveillance cameras.

Buyue Zhang