프로그램/ASP

한글 금액 표기 방법

네오류이 2021. 1. 14. 16:02
728x90
반응형

오늘은 ㅊ에서 보통 은행권이나 발주쪽 프로그램에서 사용되는 한글금액 표기하는 방법을 함수로 구현하고자 합니다.

 

사실 거의 고정코드이기에 금액자리가 무지 커지게 되면 함수를 좀 수정해야 합니다.

 

함수가 좀 길기는 하지만 잘 보시면 고정코드라는것을 아실 수 있습니다.

 

* 소스코드

 

function HanglePrice(parm_str)

 

str_len = len(parm_str)

hangle = ""

 

if str_len > 15 then

select case mid(parm_str, str_len-15, 1) 

case "1" : hangle = hangle & "일천"

case "2" : hangle = hangle & "이천"

case "3" : hangle = hangle & "삼천"

case "4" : hangle = hangle & "사천"

case "5" : hangle = hangle & "오천"

case "6" : hangle = hangle & "육천"

case "7" : hangle = hangle & "칠천"

case "8" : hangle = hangle & "팔천"

case "9" : hangle = hangle & "구천"

end select

end if

if str_len > 14 then

select case mid(parm_str, str_len-14, 1) 

case "1" : hangle = hangle & "일백"

case "2" : hangle = hangle & "이백"

case "3" : hangle = hangle & "삼백"

case "4" : hangle = hangle & "사백"

case "5" : hangle = hangle & "오백"

case "6" : hangle = hangle & "육백"

case "7" : hangle = hangle & "칠백"

case "8" : hangle = hangle & "팔백"

case "9" : hangle = hangle & "구백"

end select

end if

if str_len > 13 then

select case mid(parm_str, str_len-13, 1) 

case "1" : hangle = hangle & "일십"

case "2" : hangle = hangle & "이십"

case "3" : hangle = hangle & "삼십"

case "4" : hangle = hangle & "사십"

case "5" : hangle = hangle & "오십"

case "6" : hangle = hangle & "육십"

case "7" : hangle = hangle & "칠십"

case "8" : hangle = hangle & "팔십"

case "9" : hangle = hangle & "구십"

end select

end if

if str_len > 12 then

select case mid(parm_str, str_len-12, 1) 

case "1" : hangle = hangle & "일"

case "2" : hangle = hangle & "이"

case "3" : hangle = hangle & "삼"

case "4" : hangle = hangle & "사"

case "5" : hangle = hangle & "오"

case "6" : hangle = hangle & "육"

case "7" : hangle = hangle & "칠"

case "8" : hangle = hangle & "팔"

case "9" : hangle = hangle & "구"

end select

end if

if str_len > 12 then hangle = hangle & "조" end if

 

if str_len > 11 then

select case mid(parm_str, str_len-11, 1) 

case "1" : hangle = hangle & "일천"

case "2" : hangle = hangle & "이천"

case "3" : hangle = hangle & "삼천"

case "4" : hangle = hangle & "사천"

case "5" : hangle = hangle & "오천"

case "6" : hangle = hangle & "육천"

case "7" : hangle = hangle & "칠천"

case "8" : hangle = hangle & "팔천"

case "9" : hangle = hangle & "구천"

end select

end if

if str_len > 10 then

select case mid(parm_str, str_len-10, 1) 

case "1" : hangle = hangle & "일백"

case "2" : hangle = hangle & "이백"

case "3" : hangle = hangle & "삼백"

case "4" : hangle = hangle & "사백"

case "5" : hangle = hangle & "오백"

case "6" : hangle = hangle & "육백"

case "7" : hangle = hangle & "칠백"

case "8" : hangle = hangle & "팔백"

case "9" : hangle = hangle & "구백"

end select

end if

if str_len > 9 then

select case mid(parm_str, str_len-9, 1) 

case "1" : hangle = hangle & "일십"

case "2" : hangle = hangle & "이십"

case "3" : hangle = hangle & "삼십"

case "4" : hangle = hangle & "사십"

case "5" : hangle = hangle & "오십"

case "6" : hangle = hangle & "육십"

case "7" : hangle = hangle & "칠십"

case "8" : hangle = hangle & "팔십"

case "9" : hangle = hangle & "구십"

end select

end if

if str_len > 8 then

select case mid(parm_str, str_len-8, 1) 

case "1" : hangle = hangle & "일"

case "2" : hangle = hangle & "이"

case "3" : hangle = hangle & "삼"

case "4" : hangle = hangle & "사"

case "5" : hangle = hangle & "오"

case "6" : hangle = hangle & "육"

case "7" : hangle = hangle & "칠"

case "8" : hangle = hangle & "팔"

case "9" : hangle = hangle & "구"

end select

end if

if str_len > 12 then

if mid(parm_str, str_len-12, 4) <> "0000" then hangle = hangle & "억" end if

 

elseif str_len > 8 then 

hangle = hangle & "억"

end if

 

if str_len > 7 then

select case mid(parm_str, str_len-7, 1) 

case "1" : hangle = hangle & "일천"

case "2" : hangle = hangle & "이천"

case "3" : hangle = hangle & "삼천"

case "4" : hangle = hangle & "사천"

case "5" : hangle = hangle & "오천"

case "6" : hangle = hangle & "육천"

case "7" : hangle = hangle & "칠천"

case "8" : hangle = hangle & "팔천"

case "9" : hangle = hangle & "구천"

end select

end if

 

if str_len > 6 then

select case mid(parm_str, str_len-6, 1) 

case "1" : hangle = hangle & "일백"

case "2" : hangle = hangle & "이백"

case "3" : hangle = hangle & "삼백"

case "4" : hangle = hangle & "사백"

case "5" : hangle = hangle & "오백"

case "6" : hangle = hangle & "육백"

case "7" : hangle = hangle & "칠백"

case "8" : hangle = hangle & "팔백"

case "9" : hangle = hangle & "구백"

end select

end if

if str_len > 5 then

select case mid(parm_str, str_len-5, 1) 

case "1" : hangle = hangle & "일십"

case "2" : hangle = hangle & "이십"

case "3" : hangle = hangle & "삼십"

case "4" : hangle = hangle & "사십"

case "5" : hangle = hangle & "오십"

case "6" : hangle = hangle & "육십"

case "7" : hangle = hangle & "칠십"

case "8" : hangle = hangle & "팔십"

case "9" : hangle = hangle & "구십"

end select

end if

if str_len > 4 then

select case mid(parm_str, str_len-4, 1) 

case "1" : hangle = hangle & "일"

case "2" : hangle = hangle & "이"

case "3" : hangle = hangle & "삼"

case "4" : hangle = hangle & "사"

case "5" : hangle = hangle & "오"

case "6" : hangle = hangle & "육"

case "7" : hangle = hangle & "칠"

case "8" : hangle = hangle & "팔"

case "9" : hangle = hangle & "구"

end select

end if

if str_len > 8 then

if mid(parm_str, str_len-8, 4)  <> "0000" then hangle = hangle & "만" end if

elseif str_len > 4 then 

hangle = hangle & "만"

end if

 

if str_len > 3 then

select case mid(parm_str, str_len-3, 1) 

case "1" : hangle = hangle & "일천"

case "2" : hangle = hangle & "이천"

case "3" : hangle = hangle & "삼천"

case "4" : hangle = hangle & "사천"

case "5" : hangle = hangle & "오천"

case "6" : hangle = hangle & "육천"

case "7" : hangle = hangle & "칠천"

case "8" : hangle = hangle & "팔천"

case "9" : hangle = hangle & "구천"

end select

end if

if str_len > 2 then

select case mid(parm_str, str_len-2, 1) 

case "1" : hangle = hangle & "일백"

case "2" : hangle = hangle & "이백"

case "3" : hangle = hangle & "삼백"

case "4" : hangle = hangle & "사백"

case "5" : hangle = hangle & "오백"

case "6" : hangle = hangle & "육백"

case "7" : hangle = hangle & "칠백"

case "8" : hangle = hangle & "팔백"

case "9" : hangle = hangle & "구백"

end select

end if

if str_len > 1 then

select case mid(parm_str, str_len-1, 1) 

case "1" : hangle = hangle & "일십"

case "2" : hangle = hangle & "이십"

case "3" : hangle = hangle & "삼십"

case "4" : hangle = hangle & "사십"

case "5" : hangle = hangle & "오십"

case "6" : hangle = hangle & "육십"

case "7" : hangle = hangle & "칠십"

case "8" : hangle = hangle & "팔십"

case "9" : hangle = hangle & "구십"

end select

end if

if str_len > 0 then

select case mid(parm_str, str_len-0, 1) 

case "1" : hangle = hangle & "일"

case "2" : hangle = hangle & "이"

case "3" : hangle = hangle & "삼"

case "4" : hangle = hangle & "사"

case "5" : hangle = hangle & "오"

case "6" : hangle = hangle & "육"

case "7" : hangle = hangle & "칠"

case "8" : hangle = hangle & "팔"

case "9" : hangle = hangle & "구"

end select

end if

 

HanglePrice = hangle

 

end function

 

* 사용법

 

total_cost = 123

aaa = "금액 : "+HanglePrice(total_cost&"")+"원 정"  ' 금액 : 일백이십삼원 정

 

주의할 것은 인자 전달할 때 문자형으로 전달해야 합니다. cstr 함수를 써도 되고, 저 같은 경우 &"" 라는 방식을 많이 사용합니다. 간혹 cstr에서 에러가 나는 경우도 존재하기 때문힙니다. ( db애서 bigint 형의 값을 읽을 때 cstr 이 에러가 나는 경우가 있음)

 

그 외는 별 다른 내용이 없네요..

 

#ASP#금액#금액표기방법#한글

728x90
반응형