Q&A

  • 숫자를 한글로(여기 예제는 버그가 좀 있는듯 한데..)
unit Unit1;



interface



uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls;



type

TForm1 = class(TForm)

Button1: TButton;

Edit1: TEdit;

Label1: TLabel;

procedure Button1Click(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;



var

Form1: TForm1;



implementation

{$R *.DFM}



function Amount(N: Longint): String;

const

Units: array[0..9] of String = ('', '일', '이', '삼', '사', '오',

'육', '칠', '팔', '구');

Lower: array[0..3] of String = ('', '십','백','천');

Higher: array[0..4] of String = ('', '만','억','조','경');

HighLevel: Integer = 0;

begin

case N of

0..9: Result := Result + Units[N];

10..99:

Result := Result +

Amount(N div 10) + Lower[1] + Amount(N mod 10);

100..999:

Result := Result +

Amount(N div 100) + Lower[2] + Amount(N mod 100);

1000..9999:

Result := Result +

Amount(N div 1000) + Lower[3] + Amount(N mod 1000);

else

begin

inc(HighLevel);

Result := Result +

Amount(N div 10000) + Higher[HighLevel] + Amount(N mod 10000);

dec(HighLevel);

end;

end;

end;



procedure TForm1.Button1Click(Sender: TObject);

begin

try

Label1.caption := Amount(Trunc(StrToFloat(Edit1.Text)));

except

on EConvertError do

Label1.caption := '정확한 숫자를 입력하세요';

end;

end;



end.



이런식의 소스가 여기 있던데영..

100000000 <- 나 일억..

이라고 하면

출력 되기는 '일억만' 이라고 나옵니다.

물론 백억도 '백억만'

암튼 일억만 넘어 버리고 뒤에 계속 0값이면

만자가 붙더군요..

이를 어찌 해결 하오리까.

혹시 버그 잡아 주실분 없나영?

바꾸어 볼려고 해도.. 재귀 함수 호출 비스므리한게 들어 있어서..

추적하기도 좀 벅차내요..

그럼 고수님.. 화튕..

0  COMMENTS