써먹는 웹개발

맵 데이터의 키값을 각 형식으로 변경하는 방법 본문

웹개발/Java & Jsp

맵 데이터의 키값을 각 형식으로 변경하는 방법

kmhan 2018. 3. 10. 22:36


728x90
반응형

맵 데이터의 키값을 각 형식으로 변경하는 방법



1. 문자열 형태로 변경

protected String getMapToString(Map<String,Object> map, String strKey) {

if(map == null || map.isEmpty()) {

return "";

}

if(map.containsKey(strKey)) {

return map.get(strKey).toString();

}

return "";

}


2. 실수 형태로 변경

protected double getMapToDouble(Map<String,Object> map, String strKey) {

String strData = getMapToString(map, strKey);

if("".equals(strData)) {

return 0;

}

return Double.parseDouble(strData);

}


3. 정수 형태로 변경

protected int getInteger(String val, int defValue) {

int iResult = 0;

try {

iResult = Integer.parseInt(val);

} catch(NumberFormatException e) {

iResult = defValue;

}

retrun iResult;

}


4. 금액 표시형식 및 소수점 2자리 실수 형태로 변경

protected String getDoubleFormat(double target) {

try {

if (target == 0) return "0";


DecimalFormat df = new DecimalFormat("#,###.##");

return df.format(Math.round(target*100)/100.0);

} catch(Exception e) {

return "0";

}

}

728x90
반응형

'웹개발 > Java & Jsp' 카테고리의 다른 글

billboard.js 예제있는 주소  (0) 2018.04.30
문자열을 배열화시키는 방법 (가변 배열 만들수 있음)  (0) 2018.04.26
맵 가져오는 방법  (0) 2018.04.24
[Java]엑셀 다운로드  (0) 2018.04.16
[Java]엑셀 업로드  (0) 2018.04.16


Comments