반응형
델파이 팁 : 금액을 한글로 표현하기
금액을 한글로 변환 하는 방법 입니다.
소스내용
//Parameter : P_Value: 금액 P_Type :정 포함여부( 1: 미포함, 0; 포함)
function MoneyToHangul(P_Value : Double; P_Type : Word): String;
var LST_Value : String;
i : Integer;
// LWO_Cnt : Integer;
LBO_ZeroSkip : Boolean;
begin
Result := '';
LST_Value := '';
if P_Value > 0 then begin
LST_Value := FloatToStr(P_Value);
for i := Length(LST_Value) downto 1 do begin
LBO_ZeroSkip := False;
case StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 1), 1)) of
1 : Result := Result + '일';
2 : Result := Result + '이';
3 : Result := Result + '삼';
4 : Result := Result + '사';
5 : Result := Result + '오';
6 : Result := Result + '육';
7 : Result := Result + '칠';
8 : Result := Result + '팔';
9 : Result := Result + '구';
else
LBO_ZeroSkip := True;
end;
if not LBO_ZeroSkip then begin
case i of
2 : Result := Result + '십';
3 : Result := Result + '백';
4 : Result := Result + '천';
5 : Result := Result + '만';
6 :
begin
if StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 2), 1)) = 0 then
Result := Result + '십만'
else
Result := Result + '십';
end;
7 :
begin
if (StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 2), 1)) = 0) and
(StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 3), 1)) = 0) then
Result := Result + '백만'
else
Result := Result + '백';
end;
8 :
begin
if (StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 2), 1)) = 0) and
(StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 3), 1)) = 0) and
(StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 4), 1)) = 0) then
Result := Result + '천만'
else
Result := Result + '천';
end;
9 : Result := Result + '억';
10 :
begin
if StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 2), 1)) = 0 then
Result := Result + '십억'
else
Result := Result + '십';
end;
11 :
begin
if (StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 2), 1)) = 0) and
(StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 3), 1)) = 0) then
Result := Result + '백억'
else
Result := Result + '백';
end;
12 :
begin
if (StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 2), 1)) = 0) and
(StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 3), 1)) = 0) and
(StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 4), 1)) = 0) then
Result := Result + '천억'
else
Result := Result + '천';
end;
13 : Result := Result + '조';
14 :
begin
if StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 2), 1)) = 0 then
Result := Result + '십조'
else
Result := Result + '십';
end;
15 :
begin
if (StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 2), 1)) = 0) and
(StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 3), 1)) = 0) then
Result := Result + '백조'
else
Result := Result + '백';
end;
16 :
begin
if (StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 2), 1)) = 0) and
(StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 3), 1)) = 0) and
(StrToInt(Copy(LST_Value, Length(LST_Value) - (i - 4), 1)) = 0) then
Result := Result + '천조'
else
Result := Result + '천';
end;
else
end;
end;
end;
if P_Type = 1 then
Result := Result + '원'
else
Result := '일금'+Result + '원정';
end;
end;
구현
Value.Text := MoneyToHangul(123456,1) // 일십이만삼천사백오십육원
Value.Text := MoneyToHangul(987654,0) // 일금구십팔만칠천육백오십사원정
결과
반응형
'Developers > Delphi[델파이]' 카테고리의 다른 글
[Delphi Tip] 전화번호에 하이픈(-) 삽입 (1) | 2019.10.23 |
---|---|
[델파이] TEdit 에서 숫자만 입력 가능! (0) | 2019.10.22 |
[Delphi] String -> TStringList 전환하기 (0) | 2019.10.08 |