숫자를 한글로 표시하는 함수 추가

main
이범준 1 year ago
parent 5d79aea784
commit 921bf2ab1d

@ -287,4 +287,34 @@ public class CmmnUtil {
DecimalFormat decFormat = new DecimalFormat("###,###"); DecimalFormat decFormat = new DecimalFormat("###,###");
return decFormat.format(number); return decFormat.format(number);
} }
/** .
* @param number
* @return
*/
public static String convertNumberToHangul(String number) {
String[] han1 = { "", "일", "이", "삼", "사", "오", "육", "칠", "팔", "구" };
String[] han2 = { "", "십", "백", "천" };
String[] han3 = { "", "만", "억", "조", "경" };
String result = "";
int len = number.length();
int nowInt = 0;
boolean hasHan3 = false;
for (int i = len; i > 0; i--) {
nowInt = Integer.parseInt(number.substring(len - i, len - i + 1));
int han2Pick = (i - 1) % 4;
if (nowInt > 0) {
result += (han1[nowInt]) + (han2[han2Pick]);
if (han2Pick > 0) {
hasHan3 = false;
}
}
if (!hasHan3 && han2Pick == 0) {
result += (han3[(i - 1) / 4]);
hasHan3 = true;
}
}
return result.toString();
}
} }

Loading…
Cancel
Save