object 정수 변환 수정
This commit is contained in:
@@ -89,11 +89,34 @@ public class CommonUtils {
|
|||||||
public static Integer objectToInteger(Object object){
|
public static Integer objectToInteger(Object object){
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (object instanceof Integer) {
|
}
|
||||||
|
|
||||||
|
if (object instanceof Integer) {
|
||||||
return (Integer) object;
|
return (Integer) object;
|
||||||
} else if (object instanceof Boolean) {
|
}
|
||||||
return (Integer)object;
|
|
||||||
} else {
|
if (object instanceof Number) {
|
||||||
|
return ((Number) object).intValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object instanceof Boolean) {
|
||||||
|
return ((Boolean) object) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// String이나 다른 타입의 경우 문자열로 변환 후 처리
|
||||||
|
String strValue = String.valueOf(object).trim();
|
||||||
|
if (strValue.isEmpty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 소수점이 있는 숫자 문자열 처리
|
||||||
|
if (strValue.contains(".")) {
|
||||||
|
return (int) Double.parseDouble(strValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Integer.parseInt(strValue);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user