|
|
|
@ -8,26 +8,46 @@ import java.math.BigDecimal; |
|
|
|
public class ObjectFormatUtil { |
|
|
|
/** |
|
|
|
* 一种较为安全的Object转换Integer方式 |
|
|
|
* |
|
|
|
* @param o 要转化的对象 |
|
|
|
* @return 转化的Integer类型结果 |
|
|
|
*/ |
|
|
|
public static Integer toInteger(Object o) { |
|
|
|
return o==null?null:Integer.parseInt(o.toString()); |
|
|
|
if (o == null) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
String s = o.toString(); |
|
|
|
s = s.replaceAll(",", ""); |
|
|
|
return Integer.parseInt(s); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 一种较为安全的Object转换Long方式 |
|
|
|
* |
|
|
|
* @param o 要转化的对象 |
|
|
|
* @return 转化的Long类型结果 |
|
|
|
*/ |
|
|
|
public static Long toLong(Object o) { |
|
|
|
return o==null?null:Long.parseLong(o.toString()); |
|
|
|
if (o == null) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
String s = o.toString(); |
|
|
|
s = s.replaceAll(",", ""); |
|
|
|
return Long.parseLong(s); |
|
|
|
} |
|
|
|
|
|
|
|
public static Boolean toBoolean(Object o) { |
|
|
|
return (o == null) ? null : Boolean.parseBoolean(o.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
public static Double toDouble(Object o){return (o == null)?null:Double.parseDouble(o.toString());} |
|
|
|
public static Double toDouble(Object o) { |
|
|
|
if (o == null) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
String s = o.toString(); |
|
|
|
s = s.replaceAll(",", ""); |
|
|
|
return Double.parseDouble(s); |
|
|
|
} |
|
|
|
|
|
|
|
// double类型相加
|
|
|
|
public static double sum(double d1, double d2) { |
|
|
|
|