Revision as of 04:27, 23 November 2010 by Han84 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

EISL lab graduate

Mu Qiao