object 정수 변환 수정

This commit is contained in:
2025-02-14 12:02:03 +09:00
parent f5060e81b9
commit 2f1e2c654c

View File

@@ -89,11 +89,34 @@ public class CommonUtils {
public static Integer objectToInteger(Object object){
if (object == null) {
return 0;
} else if (object instanceof Integer) {
return (Integer)object;
} else if (object instanceof Boolean) {
return (Integer)object;
} else {
}
if (object instanceof Integer) {
return (Integer) object;
}
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;
}
}