1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444 |
- /**
- * @(#)file PCMSUtil.java
- * @(#)author
- * @(#)version 1.0
- * @(#)date 2003-05-23
- * @(#)since JDK1.3.1
- **
- * Copyright (c) 2002-2003 www.hwenc.com, Inc.
- * All rights reserved.
- * This software is the proprietary information of hwenc, Inc.
- */
- package kr.co.udapsoft.common.util;
- import java.math.BigDecimal;
- import java.text.DecimalFormat;
- import java.text.NumberFormat;
- import java.util.StringTokenizer;
- import java.util.Vector;
- import kr.co.hsnc.common.base.WAFLogger;
- import kr.co.hsnc.common.util.PatternUtil;
- import kr.co.hsnc.common.util.StringUtil;
- import kr.co.hsnc.common.util.ValueObject;
- import com.udapsoft.waf.common.util.DateUtil;
- /**
- * IPS에서 사용되는 유틸리티 메소드를 모아둔 클래스다.
- * Formatter클래스는 DateUtil.java의 facade 클래스이기도 하다.
- *
- * @author hanajava
- */
- public class PCMSUtil {
- //2004-07-01 추가
- private static final int DAY_OF_MONTH = 12;
- /** 기본 기간 설정
- * @return
- */
- public static ValueObject getDefaultPeriod() {
- return DateUtil.getDefaultPeriod();
- }
- /**
- * 현설일시 얻기(일자)
- * by hanajava
- * @param str
- * @return
- */
- public static String formatExplDate1(String str) {
- try {
- str = replace(str, "-", "");
- StringBuffer date = new StringBuffer(str.substring(0, 8));
- return date.insert(4, "-").insert(7, "-").toString();
- } catch (Exception e) {
- return "";
- }
- }
- /**
- * 현설일지 얻기(시간)
- * by hanajava
- * @param str
- * @return
- */
- public static String formatExplDate2(String str) {
- try {
- str = replace(str, "-", "");
- str = replace(str, ":", "");
- StringBuffer date = new StringBuffer(str.substring(8));
- return date.insert(2, ":").toString();
- } catch (Exception e) {
- return "";
- }
- }
- /**
- * 문자열중 대상문자열를 특정문자열로 변경한다.
- * ex) replace("hanajava", "hana", "java") -> "javajava"
- * @param line
- * @param oldStr 대상문자열
- * @param newStr 특정문자열
- * @return
- */
- /**
- public static String replace(String line, String oldStr, String newStr){
- /*if(line == null || line.length() == 0){
- return "";
- }
- int index = 0;
- while((index = line.indexOf(oldStr, index)) >= 0){
- line = line.substring(0, index) + newStr + line.substring(index+oldStr.length());
- index += newStr.length();
- }
- return line;
- return org.apache.commons.lang.StringUtils.replace (line, oldStr, newStr);
- }
- */
- /**
- * 문자열중 대상문자열를 특정문자열로 변경한다.
- * ex) replace("hanajava", "hana", "java") -> "javajava"
- * @param line
- * @param oldStr 대상문자열
- * @param newStr 특정문자열
- * @return
- */
- public static String replace(String line, String oldStr, String newStr) {
- if (line == null || line.length() == 0) {
- return "";
- }
- int index = 0;
- while ((index = line.indexOf(oldStr, index)) >= 0) {
- line = line.substring(0, index) + newStr
- + line.substring(index + oldStr.length());
- index += newStr.length();
- }
- return line;
- //return org.apache.commons.lang.StringUtils.replace (line, oldStr, newStr);
- }
- /**
- * html 에 스페이스( ) 추가
- * @param cnt
- * @return
- */
- public static String addSpace(String cnt) {
- return addSpace(Integer.parseInt(cnt));
- }
- /**
- * html 에 스페이스( ) 추가
- * @param cnt
- * @return
- */
- public static String addSpace(int cnt) {
- StringBuffer strBuf = new StringBuffer();
- if (cnt < 1)
- return "";
- for (int i = 0; i < cnt; i++)
- strBuf.append(" ");
- return strBuf.toString();
- }
- /**
- * 숫자를 한글로 변경한다.
- * 12345678 -> 일천이백삼십사만오천유백칠십팔
- * @param number
- * @return
- */
- public static String toHangle(long number) {
- String rtnStr = "";
- String numStr = Long.toString(number);
- String[] bigUnitArray = { "", "만", "억", "조" };
- String[] unitArray = { "", "십", "백", "천" };
- String[] hanArray = { "", "일", "이", "삼", "사", "오", "육", "칠", "팔", "구" };
- Vector splitedNum = new Vector();
- int pos = numStr.length();
- int index = 0;
- while (true) {
- if (pos - 4 > 0) {
- splitedNum.add(numStr.substring(pos - 4, pos));
- } else {
- splitedNum.add(numStr.substring(0, pos));
- break;
- }
- pos = pos - 4;
- index++;
- }
- int tmpLen = 0;
- int splietedNumSize = splitedNum.size();
- String tmp = "";
- for (int i = splietedNumSize - 1; i >= 0; i--) {
- tmp = (String) splitedNum.get(i);
- tmpLen = ((String) splitedNum.get(i)).length();
- for (int j = tmpLen; j > 0; j--) {
- String s = tmp.substring((tmpLen - j), (tmpLen - j) + 1);
- if (s.equals("0"))
- continue;
- /* by jetdoc */
- /*
- if( s.equals("1") && j != 1 && !(i == splietedNumSize-1 && j == tmpLen) ) {
- rtnStr += unitArray[j-1];
- }
- else {
- rtnStr += hanArray[Integer.parseInt(s)] + unitArray[j-1];
- }
- */
- if (s.equals("-")) {
- rtnStr += s;
- } else {
- rtnStr += hanArray[Integer.parseInt(s)] + unitArray[j - 1];
- }
- }
- if (!tmp.equals("-") && Integer.parseInt(tmp) != 0)
- rtnStr += bigUnitArray[i];
- }
- return rtnStr;
- }
- /**
- * 소수점을 적용하여 숫자를 한글로 변경한다. -2010.12.07 한지훈
- * 12345678.12 -> 일천이백삼십사만오천유백칠십팔.일이
- * @param number
- * @return
- */
- public static String toHangule_decimal(String amt) {
- String rtnStr = "";
- String rtnStr_decimal = "";
- String numStr = StringUtil.replace(amt,",","");
- String numStr_decimal = StringUtil.replace(amt,",","");
- String[] bigUnitArray = { "", "만", "억", "조" };
- String[] unitArray = { "", "십", "백", "천" };
- String[] hanArray = { "", "일", "이", "삼", "사", "오", "육", "칠", "팔", "구" };
- String[] hanArray_decimal = { "영", "일", "이", "삼", "사", "오", "육", "칠", "팔", "구" };
- Vector splitedNum = new Vector();
- int decimal_pos = numStr.indexOf(".");
-
- if (decimal_pos == -1) {
- numStr = numStr.substring(0, numStr.length());
- }else {
- numStr = numStr.substring(0, decimal_pos);
- numStr_decimal = numStr_decimal.substring(decimal_pos+1, numStr_decimal.length());
- }
-
- int pos = numStr.length();
- int pos_decimal = numStr_decimal.length();
- int index = 0;
- while (true) {
- if (pos - 4 > 0) {
- splitedNum.add(numStr.substring(pos - 4, pos));
- } else {
- splitedNum.add(numStr.substring(0, pos));
- break;
- }
- pos = pos - 4;
- index++;
- }
- int tmpLen = 0;
- int splietedNumSize = splitedNum.size();
- String tmp = "";
- for (int i = splietedNumSize - 1; i >= 0; i--) {
- tmp = (String) splitedNum.get(i);
- tmpLen = ((String) splitedNum.get(i)).length();
- for (int j = tmpLen; j > 0; j--) {
- String s = tmp.substring((tmpLen - j), (tmpLen - j) + 1);
- if (s.equals("0"))
- continue;
- if (s.equals("-")) {
- rtnStr += s;
- } else {
- rtnStr += hanArray[Integer.parseInt(s)] + unitArray[j - 1];
- }
- }
- if (!tmp.equals("-") && Integer.parseInt(tmp) != 0)
- rtnStr += bigUnitArray[i];
- }
- if (decimal_pos != -1) {
- rtnStr_decimal = ".";
- for (int j = pos_decimal; j > 0; j--) {
- String m = numStr_decimal.substring((pos_decimal - j), (pos_decimal - j) + 1);
- rtnStr_decimal += hanArray_decimal[Integer.parseInt(m)];
- }
- }
- return rtnStr+rtnStr_decimal;
- }
-
- /** 1.1.1 ---> 01.01.01 로 변환
- * by jetdoc
- * @param str
- * @param len
- * @return
- */
- public static String lpad4Dot(String str, int len) {
- String[] strList = null;
- StringBuffer strBuf = new StringBuffer();
- strList = PatternUtil.split(str, ".");
- for (int i = 0; i < strList.length; i++) {
- strBuf.append(StringUtil.lpad(strList[i], len));
- if (i != strList.length - 1)
- strBuf.append(".");
- }
- return strBuf.toString();
- }
- public static float doRound(float num) {
- return doRound(num, 3);
- }
- public static double doRound(double num) {
- return doRound(num, 3);
- }
- /** 반올림 함수 ( JDK 1.4부터 지원 : JDK1.3을 위해 구현 )
- * by jetdoc
- * @param num
- * @param pos
- * @return
- */
- public static float doRound(float num, int pos) {
- double posV;
- if (pos == 0) {
- posV = 1;
- } else {
- posV = Math.pow(10, (double) pos);
- }
- return (float) (Math.round(num * posV) / posV);
- }
- /** 반올림 함수 ( JDK 1.4부터 지원 : JDK1.3을 위해 구현 )
- * by jetdoc
- * @param num
- * @param pos
- * @return
- */
- public static double doRound(double num, int pos) {
- double posV;
- if (pos == 0) {
- posV = 1;
- } else {
- posV = Math.pow(10, (double) pos);
- }
- return (Math.round(num * posV) / posV);
- }
- /**
- * 금액 0원일때 "" 리턴
- * @param cnt
- * @return
- */
- /*
- public static String zeroSpace(String str){
-
- if(str.equals("0")) str = "";
- return str;
- }
- */
- /******추가***************SSS*************************************************/
- /**
- * 이전달 구하기
- *
- * @param String
- * @return String
- * @exception
- */
- public static String getBeforeMonth(String yyyymm) {
- if (yyyymm.equals(""))
- return "";
- String pre_month = "";
- String s_month = "";
- String s_year = yyyymm.substring(0, 4);
- int i_month = Integer.parseInt(yyyymm.substring(4, 6));
- i_month--;
- if (i_month == 0) {
- i_month = 12;
- s_year = Integer.parseInt(s_year) - 1 + "";
- }
- if (i_month < 10)
- s_month = "0" + i_month;
- else
- s_month = i_month + "";
- pre_month = s_year + s_month;
- return pre_month;
- }
- /**
- *@param yyyymmdd
- *@return
- *기 능 : 하루 전 일자 가져오기
- *@author seafrog(pck)
- *@version 2006. 4. 23
- *@since JDK1.3
- *----------------------------------------------------------
- */
- public static String getBeforeDay(String yyyymmdd) {
- java.text.SimpleDateFormat formatt = new java.text.SimpleDateFormat(
- "yyyyMMdd");
- java.util.Calendar calenda = java.util.Calendar.getInstance();
- java.util.Date date = null;
- try {
- date = formatt.parse(yyyymmdd);
- calenda.setTime(date);
- calenda.add(java.util.Calendar.DAY_OF_YEAR, -1);
- yyyymmdd = formatt.format(calenda.getTime());
- } catch (Exception ex) {
- }
- return yyyymmdd;
- }
- /**
- * 다음달 구하기
- *
- * @param year : 년도 month : 달
- * @return String
- * @exception
- */
- public static String nextMonthofYear(String yyyymm) {
- String nextyear = "";
- String nextmonth = "";
- String nextyearmonth = "";
- if (yyyymm.length() == 6) {
- int year = Integer.parseInt(yyyymm.substring(0, 4));
- int month = Integer.parseInt(yyyymm.substring(4));
- if (month == 12) {
- nextmonth = "01";
- nextyear = String.valueOf(year + 1);
- } else {
- if ((month + 1) < 10) {
- nextmonth = "0" + (month + 1);
- } else {
- nextmonth = String.valueOf(month + 1);
- }
- nextyear = String.valueOf(year);
- }
- nextyearmonth = nextyear + nextmonth;
- return nextyearmonth;
- } else {
- return yyyymm;
- }
- }
- /**
- * xxx 구분자로 구분하여 토큰을 얻는다.
- * @param str 문자열
- * @param delim 구분자
- * @return 토큰
- */
- public static String[] getTokens(String str, String delim) {
- StringTokenizer st = new StringTokenizer(str, delim);
- int size = st.countTokens();
- String[] tokens = new String[size];
- for (int i = 0; st.hasMoreTokens(); i++) {
- tokens[i] = st.nextToken();
- }
- return tokens;
- }
- /******추가***************EEE*************************************************/
- /**
- * 금액 표시
- *
- * @param num 금액
- * @return String
- * @exception
- */
- public static String convType(double num) {
- return NumberFormat.getInstance().format(num);
- }
- public static String convType(long num) {
- return NumberFormat.getInstance().format(num);
- }
- public static String convType(int num) {
- return NumberFormat.getInstance().format(num);
- }
- public static String convType(String str) {
- return NumberFormat.getInstance().format(Double.parseDouble(str));
- }
- //double형 금액, 자리수 올림
- public static String convType(double num, int pos) {
- String str = "";
- num = doRound(num, pos);
- str = num + "";
- //WAFLogger.debug("str == [" + str + "]");
- //정수자리에 금액을 표시하는 ,를 추가한다.
- str = convType(str);
- str = strPoint(str, pos); //자리수조정..예: pos가 2인겨우 0.2 ===> 0.20으로
- //str = convType( str );
- return str;
- //return NumberFormat.getInstance().format(num);
- }
-
-
- /**
- * 0원인 경우 표시하지 않음
- * @param num
- * @param pos
- * @return
- */
- public static String convTypeNoZero(double num, int pos) {
-
- String str = "";
- num = doRound(num, pos);
-
- str = num + "";
- str = convType(str);
-
- str = strPoint(str, pos); //자리수조정..예: pos가 2인겨우 0.2 ===> 0.20으로
-
- if (num == 0) {
- str = "";
- }
- return str;
- }
- /****************************************************************
- --(2006-12-03 추가) 시작
- --강묵 2006-12-03 기본관리 평형/약정관리 데이터 입력시 오류 처리를 위한 류진환의 요청으로 추가
- ****************************************************************/
- public static String convType_house(double num, int pos) {
- String str = "";
- String pointRight = "";
- num = doRound(num, pos);
- str = num + "";
- if (str.indexOf(".") != -1) //소수점이 존재하는 경우
- {
- pointRight = str.substring(str.indexOf("."), str.length()); // 소수점을 포함해서 소수점 이하 부분을 저장한다.
- str = str.substring(0, str.indexOf(".")); // 소수점 이전 부분 즉 정수부분을 저장한다.
- str = convType(str) + pointRight; // 정수부분에 금액을 표시하는 ,를 추가하고 저장해놓은 소수점 이하부분을 더하여 저장한다.
- } else { // 소수점이 존재하지 않는 경우
- str = convType(str);
- }
- str = strPoint(str, pos); //자리수조정..예: pos가 2인겨우 0.2 ===> 0.20으로
- return str;
- }
- /****************************************************************
- --(2006-12-03 추가) 끝
- ****************************************************************/
- // 소수이하 절삭 함수
- public static String convert(double doubleObj, String pattern)
- throws Exception {
- DecimalFormat df = new DecimalFormat(pattern);
- return df.format(doubleObj).toString();
- }
- ///////////////////////////////////////////////////////
- //절삭(truncate) 메소드
- //@param data 입력 데이터. double 타입.
- //@param pos 절삭될 위치. int 타입
- //@return 절삭된 결과. double 타입.
- private static double[] lowUnits = { 1.0, 1.0E-1, 1.0E-2, 1.0E-3, 1.0E-4,
- 1.0E-5, 1.0E-6, 1.0E-7, 1.0E-8, 1.0E-9, 1.0E-10, 1.0E-11, 1.0E-12,
- 1.0E-13, 1.0E-14, 1.0E-15, 1.0E-16 };
- private static double[] highUnits = { 1.0, 1.0E1, 1.0E2, 1.0E3, 1.0E4,
- 1.0E5, 1.0E6, 1.0E7, 1.0E8, 1.0E9, 1.0E10, 1.0E11, 1.0E12, 1.0E13,
- 1.0E14, 1.0E15, 1.0E16 };
- public static double truncate(double data, int pos) {
- if (pos == 0)
- return Math.floor(data);
- else if (pos > 0 && pos <= highUnits.length)
- return lowUnits[pos] * Math.floor(data * highUnits[pos]);
- else if (pos < 0 && pos >= -lowUnits.length)
- return highUnits[-pos] * Math.floor(data * lowUnits[-pos]);
- else
- throw new RuntimeException(data
- + " cannot be truncated at the position " + pos);
- }
- ///////////////////////////////////////////////////////
- // 잘라내림(floor) 메소드
- // @param data 입력 데이터. double 타입.
- // @param pos 잘라내릴 위치. int 타입
- // @return 잘라내린 결과. double 타입.
- public static double floor(double data, int pos) {
- if (data >= 0.0) {
- if (pos == 0)
- return Math.floor(data);
- else if (pos > 0 && pos <= highUnits.length)
- return lowUnits[pos] * Math.floor(data * highUnits[pos]);
- else if (pos < 0 && pos >= -lowUnits.length)
- return highUnits[-pos] * Math.floor(data * lowUnits[-pos]);
- else
- throw new RuntimeException(data
- + " cannot be floored at the position " + pos);
- } else {
- if (pos == 0)
- return -Math.ceil(-data);
- else if (pos > 0 && pos <= highUnits.length)
- return lowUnits[pos] * -Math.ceil(-data * highUnits[pos]);
- else if (pos < 0 && pos >= -lowUnits.length)
- return highUnits[-pos] * -Math.ceil(-data * lowUnits[-pos]);
- else
- throw new RuntimeException(data
- + " cannot be truncated at the position " + pos);
- }
- }
- ///////////////////////////////////////////////////////
- // 잘라올림(ceil) 메소드
- // @param data 입력 데이터. double 타입.
- // @param pos 잘라올릴 위치. int 타입
- // @return 잘라올린 결과. double 타입.
- public static double ceil(double data, int pos) {
- if (data >= 0.0) {
- if (pos == 0)
- return Math.ceil(data);
- else if (pos > 0 && pos <= highUnits.length)
- return lowUnits[pos] * Math.ceil(data * highUnits[pos]);
- else if (pos < 0 && pos >= -lowUnits.length)
- return highUnits[-pos] * Math.ceil(data * lowUnits[-pos]);
- else
- throw new RuntimeException(data
- + " cannot be ceiled at the position " + pos);
- } else {
- if (pos == 0)
- return -Math.floor(-data);
- else if (pos > 0 && pos <= highUnits.length)
- return lowUnits[pos] * -Math.floor(-data * highUnits[pos]);
- else if (pos < 0 && pos >= -lowUnits.length)
- return highUnits[-pos] * -Math.floor(-data * lowUnits[-pos]);
- else
- throw new RuntimeException(data
- + " cannot be floored at the position " + pos);
- }
- }
- ///////////////////////////////////////////////////////
- // 반올림(round) 메소드
- // @param data 입력 데이터. double 타입.
- // @param pos 반올림할 위치. int 타입
- // @return 반올림된 결과. double 타입.
- public static double round(double data, int pos) {
- if (data >= 0.0) {
- if (pos == 0)
- return Math.floor(data + 0.5);
- else if (pos > 0 && pos <= highUnits.length)
- return lowUnits[pos] * Math.floor(data * highUnits[pos] + 0.5);
- else if (pos < 0 && pos >= -lowUnits.length)
- return highUnits[-pos]
- * Math.floor(data * lowUnits[-pos] + 0.5);
- else
- throw new RuntimeException(data
- + " cannot be floored at the position " + pos);
- } else {
- if (pos == 0)
- return -Math.floor(-data + 0.5);
- else if (pos > 0 && pos <= highUnits.length)
- return lowUnits[pos]
- * -Math.floor(-data * highUnits[pos] + 0.5);
- else if (pos < 0 && pos >= -lowUnits.length)
- return highUnits[-pos]
- * -Math.floor(-data * lowUnits[-pos] + 0.5);
- else
- throw new RuntimeException(data
- + " cannot be truncated at the position " + pos);
- }
- }
- public static String convertFloor(double doubleObj, int position)
- throws Exception {
- String temp = "";
- String tempTwoDigit = "";
- int inx = 0;
- String patternAttachedZero = "";
- String point = ".";
- if (position < 0)
- throw new Exception(" Position 을 0 이상으로 설정 하십시오 ");
- if (position == 0)
- point = ""; // 소수점이 포함되어 나타나는것 방지
- // doubleObj : 0, 0.xxx 인 경우 오류 수정 2010.08.27 김영수.
- temp = convert(doubleObj, "#0.0000000000000000000000000000000000");
- // BigDecimal 에서 표현하는 소수점 가장 끝자리까지 이므로
- //반올림되어 오류가 나는 소지를 최소화 한다.
- inx = temp.lastIndexOf(".");
- tempTwoDigit = temp.substring(0, ((inx + 1) + position));
- for (int i = 0; i < position; i++) {
- patternAttachedZero += "0";
- }
- return convert(Double.parseDouble(tempTwoDigit), "#,##0" + point
- + patternAttachedZero);
- }
-
-
- /**
- * @param doubleObj
- * @param position
- * @return
- * @throws Exception
- */
- public static String convertFloorNoZero(double doubleObj, int position) throws Exception {
- if (doubleObj == 0) {
- return "";
- } else {
- String temp = "";
- String tempTwoDigit = "";
- int inx = 0;
- String patternAttachedZero = "";
- String point = ".";
-
- if (position < 0)
- throw new Exception(" Position 을 0 이상으로 설정 하십시오 ");
- if (position == 0)
- point = ""; // 소수점이 포함되어 나타나는것 방지
-
- // doubleObj : 0, 0.xxx 인 경우 오류 수정 2010.08.27 김영수.
- temp = convert(doubleObj, "#0.0000000000000000000000000000000000");
- // BigDecimal 에서 표현하는 소수점 가장 끝자리까지 이므로
- //반올림되어 오류가 나는 소지를 최소화 한다.
- inx = temp.lastIndexOf(".");
- tempTwoDigit = temp.substring(0, ((inx + 1) + position));
-
- for (int i = 0; i < position; i++) {
- patternAttachedZero += "0";
- }
-
- return convert(Double.parseDouble(tempTwoDigit), "#,##0" + point + patternAttachedZero);
- }
- }
- /**
- * 해당문자의 소숫점(int point까지)을 마추어준다.
- * 2004-06-07 sukjin chang
- * @param String str, int point
- * @return String
- * @exception
- */
- public static String strPoint(String str, int point) {
- if (str == null)
- return "";
- String zero = "0000000000";
- if (str.equals(""))
- str = "0";
- if (str.indexOf(".") != -1) {
- int p = str.indexOf(".");
- str = str + zero;
- str = str.substring(0, str.indexOf(".") + 1 + point);
- } else {
- str = str + "." + zero;
- str = str.substring(0, str.indexOf(".") + 1 + point);
- }
- //2004-10-20 추가
- if (point == 0)
- str = str.substring(0, str.indexOf("."));
- return str;
- }
- /**
- * rate를 나타내는 format.
- *
- * @param pRate raw string
- * @return formatted string
- */
- public static String formatRate(String pRate, int pPost) {
- String vReturn = null;
- if (pRate == null)
- return "";
- if (pPost <= 0)
- return pRate;
- if (pRate.length() <= pPost)
- return pRate;
- int vIndex = pRate.length() - pPost;
- vReturn = convType(pRate.substring(0, vIndex));
- vReturn = vReturn + "." + pRate.substring(vIndex);
- return vReturn;
- }
- /**
- * 날짜 포맷 맞추기
- * 2004-06-02 sukjin chang
- * @param String str, String format
- * @return String
- * @exception
- */
- public static String dateFormat(String str, String format) {
- if (str == null)
- return "";
- str = str.trim();
- if (str.length() == 6) {
- return str.substring(0, 4) + format + str.substring(4);
- } else if (str.length() == 8) {
- return str.substring(0, 4) + format + str.substring(4, 6) + format
- + str.substring(6);
- } else {
- return str;
- }
- }
- /**
- * 시간 포맷 맞추기
- * 2006-01-12 Sunwoo Park
- * @param String str(HHMM)
- * @return String
- * @exception
- */
- public static String timeFormat(String str) {
- if (str == null)
- return "";
- str = str.trim();
- if (str != null && str.length() == 4) {
- return str.substring(0, 2) + ":" + str.substring(2, 4);
- } else {
- return "";
- }
- }
- /**
- * 금액에 -가 붙어있는 경우 ▼로 치환한다
- * ,자릿수 콤마가 없다면 추가한다.
- * @param str
- * @param color
- * @return
- */
- public static String setNSymbol(String str, String color) {
- int idx = str.indexOf("-");
- //맨 앞에 minus 기호가 붙어있는 경우 ▼ 로 치환한다.
- if (idx == 0) {
- if (str.indexOf(",") == -1) {
- str = convType(str);
- }
- //△ ▲ ▽ ▼
- str = str.replace('-', '▼');
- str = "<font color=" + color + ">" + str + "</font>";
- }
- return str;
- }
- /**
- * -금액의 경우 -제거후 색추가
- * 2004-06-02 sukjin chang
- * @param String str, String color
- * @return String
- * @exception
- */
- public static String strColor(String str, String color) {
- if (str == null)
- return "";
- if (str.indexOf("-") != -1) {
- str = "<font color=" + color + ">"
- + StringUtil.replace(str, "-", "△") + "</font>";
- }
- return str;
- }
- /**
- * -금액의 경우 -제거후 색추가
- * 2004-06-02 sukjin chang
- * @param String str, String color
- * @return String
- * @exception
- */
- public static String setColor(String str, String color) {
- if (str == null)
- return "";
- str = "<font color=" + color + ">" + str + "</font>";
- return str;
- }
- /**
- * -금액의 경우 -제거후 색추가
- * 2004-06-02 sukjin chang
- * @param String str, String color
- * @return String
- * @exception
- */
- public static String setColor(String str, String color, String gubun) {
- if (str == null)
- return "";
- if (gubun.equals("N"))
- str = "<font color=" + color + ">"
- + StringUtil.replace(str, "-", "") + "</font>";
- else
- str = "<font color=" + color + ">" + str + "</font>";
- return str;
- }
- /**
- * 두 날짜를 비교하여 일수를 리턴한다.
- * 2004-07-01 추가 sukjin chang
- * @param dbDate 시작일
- * @param inDate 끝일
- * @return int
- * @exception
- */
- public static int getDays(String dbDate, String inDate) {
- if ((dbDate == null || dbDate.equals("") || dbDate.length() != 8)
- && (inDate == null || inDate.equals("") || inDate.length() != 8)) {
- return 0;
- }
- if (Integer.parseInt(dbDate) > Integer.parseInt(inDate))
- return 0;
- int dbyyyy = Integer.parseInt(dbDate.substring(0, 4));
- int inyyyy = Integer.parseInt(inDate.substring(0, 4));
- int dbmm = Integer.parseInt(dbDate.substring(4, 6));
- int inmm = Integer.parseInt(inDate.substring(4, 6));
- int dbdd = Integer.parseInt(dbDate.substring(6));
- int indd = Integer.parseInt(inDate.substring(6));
- int days = 0; // 그 해의 총 일수
- if (inyyyy == dbyyyy) {
- if (inmm == dbmm) {
- days = indd - dbdd;
- } else {
- days += getMonOfDays(dbmm, dbyyyy) - dbdd; // 그달의 남은 일수 계산
- dbmm++;
- while (true) {
- if (inmm == dbmm)
- break;
- days += getMonOfDays(dbmm, dbyyyy); // 중간 차이가 나는 달의 일수 계산
- dbmm++;
- } // end of while
- days += indd; // 그달까지의 지나간 날짜 계산
- } // end of if
- } else {
- int n_dbmm = dbmm;
- for (int j = 0; j < (DAY_OF_MONTH - dbmm); j++) {
- days += getMonOfDays(++n_dbmm, dbyyyy); // 남아있는 개월수의 날짜 총합
- } // end of for
- days += getMonOfDays(dbmm, dbyyyy) - dbdd;
- dbyyyy++;
- while (true) {
- if (dbyyyy == inyyyy)
- break;
- for (int i = 1; i < 13; i++) {
- days += getMonOfDays(i, dbyyyy);
- } // end of for
- dbyyyy++;
- } // end of while
- for (int j = 1; j < inmm; j++) {
- days += getMonOfDays(j, inyyyy); // 남아있는 개월수의 날짜 총합
- } // end of for
- days += indd;
- } // end of else
- return days;
- } // end of function
- /**
- * 그해 그달의 일수 구하기
- * 2004-07-01 추가
- * @param month 달
- * @param year 년
- * @return int
- * @exception
- */
- public static int getMonOfDays(int month, int year) {
- switch (month) {
- case 1:
- case 3:
- case 5:
- case 7:
- case 8:
- case 10:
- case 12:
- return (31);
- case 4:
- case 6:
- case 9:
- case 11:
- return (30);
- default:
- if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
- return (29); // 2월 윤년계산을 위해서
- else
- return (28);
- }
- }
- /**
- * 금액 ""원일때 0 리턴
- * @param cnt
- * @return
- */
- public static String space_Zero(String str) {
- if (str.equals(""))
- str = "0";
- return str;
- }
- /**
- * 금액 "0"원일때 "" 리턴
- * @param cnt
- * @return
- */
- public static String Zero_space(String str) {
- if (str.equals("0"))
- str = "";
- else if (str.equals("0.0"))
- str = "";
- else if (str.equals("0.00"))
- str = "";
- else if (str.equals("0.000"))
- str = "";
- return str;
- }
- public static String Zero_space(float flt) {
- if (flt == 0)
- return "";
- return String.valueOf(flt);
- }
- public static String Zero_space(long lg) {
- if (lg == 0)
- return "";
- return String.valueOf(lg);
- }
- public static String Zero_space(double db) {
- if (db == 0)
- return "";
- return String.valueOf(db);
- }
- /**
- * 문자열 제거
- * @param src
- * @param target
- * @return
- */
- /**
- public static String removeString (String src, String target) {
- return org.apache.commons.lang.StringUtils.remove (src, target);
- }
-
- public static boolean isNumeric(String src) {
- return org.apache.commons.lang.StringUtils.isNumeric (src);
- }
-
- public static double toDouble (String src) {
- return org.apache.commons.lang.math.NumberUtils.toDouble (src, 0);
- }
-
- public static float toFloat (String src) {
- return org.apache.commons.lang.math.NumberUtils.toFloat (src, 0);
- }
-
- public static long toLong (String src) {
- return org.apache.commons.lang.math.NumberUtils.toLong (src, 0);
- }
-
- public static int toInt (String src) {
- return org.apache.commons.lang.math.NumberUtils.toInt (src, 0);
- }
-
- public static boolean isEmptyOrBlank (String src) {
- return org.apache.commons.lang.StringUtils.isBlank (src) || org.apache.commons.lang.StringUtils.isEmpty (src) ;
- }
- */
- /**
- * javascript escape로 유니코드로 변환된 문자열을 디코딩한다.
- *
- * @author cmlee
- * @param uni javascript의 escape로 변환된 유니코드 문자열
- * @return String
- */
- public static String unescape(String uni) {
- StringBuffer str = new StringBuffer();
- for (int i = uni.indexOf("%u"); i > -1; i = uni.indexOf("%u")) {
- str.append(uni.substring(0, i));
- str.append(String.valueOf((char) Integer.parseInt(uni.substring(
- i + 2, i + 6), 16)));
- uni = uni.substring(i + 6);
- }
- str.append(uni);
- return str.toString();
- }
- public static String[] getTokenArray(String str, String strDelim) {
- if (str == null || str.length() == 0) {
- String[] temp = { "" };
- return temp;
- }
- StringTokenizer st = new StringTokenizer(str, strDelim);
- if (st.countTokens() == 0) {
- String[] arrToken = new String[1];
- arrToken[0] = str;
- return arrToken;
- }
- String[] arrToken = new String[st.countTokens()];
- for (int i = 0; i < arrToken.length; i++)
- arrToken[i] = st.nextToken().trim();
- return arrToken;
- }
- static char[] chars = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
- 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
- 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
- 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
- public static String getRandomString(int size) {
- if (size < 1) {
- return "";
- }
- String returnStr = "";
- for (int i = 0; i < size; i++) {
- returnStr += getRandomChar();
- }
- return returnStr;
- }
- public static char getRandomChar() {
- return chars[(int) (Math.random() * 62)];
- }
- //skw 추가 2008.08.26
- public static boolean isEmptyOrBlank(String src) {
- return org.apache.commons.lang.StringUtils.isBlank(src)
- || org.apache.commons.lang.StringUtils.isEmpty(src);
- }
- //skw 추가 2008.08.26
- public static int toInt(String src) {
- return org.apache.commons.lang.math.NumberUtils.toInt(src, 0);
- }
- //skw 추가 2008.08.26
- public static long toLong(String src) {
- return org.apache.commons.lang.math.NumberUtils.toLong(src, 0);
- }
-
- //이형택 추가 2008/12/18
- public static double toDouble(String src) {
- return org.apache.commons.lang.math.NumberUtils.toDouble(src, 0);
- }
- // 이형택 추가 2008/12/18
- public static float toFloat(String src) {
- return org.apache.commons.lang.math.NumberUtils.toFloat(src, 0);
- }
- // 이형택 추가 2008/12/18
- public static boolean isNumeric(String src) {
- return org.apache.commons.lang.StringUtils.isNumeric (src);
- }
-
- //skw 추가 2008.10.02
- public static String removeString (String src, String target) {
- return org.apache.commons.lang.StringUtils.remove (src, target);
- }
-
- /**
- * BigDecimal 형태로 변환하여 계산(곱하기)
- * 2010-11-27 Giwan Choe
- * @param Double src(곱할대상), Double src(곱할수)
- * @return Double
- * @exception
- */
- public static double multiply(double src1, double src2) {
- double returnVal = 0;
-
- BigDecimal dcSrc1 = new BigDecimal(src1 + "");
- BigDecimal dcSrc2 = new BigDecimal(src2 + "");
-
- returnVal = dcSrc1.multiply(dcSrc2).doubleValue();
-
- return returnVal;
- }
-
- /**
- * BigDecimal 형태로 변환하여 계산(나누기)
- * 2010-11-27 Giwan Choe
- * @param Double src(나눌대상), Double src(나눌수)
- * @return Double
- * @exception
- */
- public static double divide(double src1, double src2) {
- double returnVal = 0;
-
- BigDecimal dcSrc1 = new BigDecimal(src1 + "");
- BigDecimal dcSrc2 = new BigDecimal(src2 + "");
-
- returnVal = dcSrc1.divide(dcSrc2, 16, 6).doubleValue();
-
- return returnVal;
- }
- /**
- * BigDecimal 형태로 변환하여 계산(곱하기)
- * 2010-11-27 Giwan Choe
- * @param String src(곱할대상), String src(곱할수)
- * @return Double
- * @exception
- */
- public static double multiply(String src1, String src2) {
- double returnVal = 0;
-
- BigDecimal dcSrc1 = new BigDecimal(src1);
- BigDecimal dcSrc2 = new BigDecimal(src2);
-
- returnVal = dcSrc1.multiply(dcSrc2).doubleValue();
-
- return returnVal;
- }
-
- /**
- * BigDecimal 형태로 변환하여 계산(나누기)
- * 2010-11-27 Giwan Choe
- * @param String src(나눌대상), String src(나눌수)
- * @return Double
- * @exception
- */
- public static double divide(String src1, String src2) {
- double returnVal = 0;
-
- BigDecimal dcSrc1 = new BigDecimal(src1);
- BigDecimal dcSrc2 = new BigDecimal(src2);
-
- returnVal = dcSrc1.divide(dcSrc2, 16, 6).doubleValue();
-
- return returnVal;
- }
-
- /**
- * 마이너스, 소수점자리수가 있는 숫자형 문자열에 comma를 붙여주는 함수
- * 2011-01-20 김영수
- * @param amount 금액
- * @return String 콤마가 붙인 숫자(-,소수점 자리수 포함)
- * @throws Exception
- */
- public static String addComma(String amount) throws Exception {
- String[] dotPos = amount.split("\\.");
- String sign = "";
- String dotU = "";
- String dotD = "";
-
- dotU = dotPos[0];
-
- if(dotU.indexOf("-") == 0) {
- sign = dotU.substring(0, 1);
- dotU = dotU.substring(1);
- }
-
- if(!PCMSUtil.isNumeric(dotU)) {
- throw new Exception("숫자가 아납니다.");
- }
- if(dotPos.length == 2) {
- dotD = dotPos[1];
- }
-
- int length = dotU.length();
- int commaFlag = length%3;
- String temp = "";
- if(commaFlag > 0) {
- temp = dotU.substring(0, commaFlag);
-
- if (length > 3) {
- temp += ",";
- }
- } else {
- temp = "";
- }
- for (int i=commaFlag; i < length; i+=3) {
- temp += dotU.substring(i, i+3);
- if( i < (length-3)) {
- temp += ",";
- }
- }
- if(!"".equals(dotD)) {
- amount = temp + "." + dotD;
- } else {
- amount = temp;
- }
-
- if("-".equals(sign)) {
- amount = sign + amount;
- }
-
- return amount;
- }
-
- /**
- * [설명]
- * 시간 형식 변형
- *
- * @param string strTime
- * @return string
- */
- public static String setConvertTime(String strTime) {
- if (strTime.length() == 6) {
- return strTime.substring(0,2) + ":" + strTime.substring(2,4) + ":" + strTime.substring(4,6);
- } else if (strTime.length() == 4) {
- return strTime.substring(0,2) + ":" + strTime.substring(2,4);
- } else {
- return strTime;
- }
- }
-
- /**
- * [설명]
- * 카드번호 형식 변형
- *
- * @param string strCardNum
- * @return string
- */
- public static String setConvertCard(String strCardNum) {
- if (strCardNum.length() == 16) {
- return strCardNum.substring(0,4) + "-" + strCardNum.substring(4,8) + "-" + strCardNum.substring(8,12) + "-" + strCardNum.substring(12,16);
- } else {
- return strCardNum;
- }
- }
- }
|