hn4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com
Full version available at http://4u.jcisio.com/r/article395.htm

Không rõ

Chuyển tiền từ số thành chữ (TP)

(Hoàng Minh)

Chương trình sau cũng có chức năng tương tự hàm ở câu 10, nhưng đọc nhanh hơn và làm việc với các số rất lớn.

(* This program analyses natural numbers only *)

Function VND(strNum:string):string;

Const levelNum:array [1..3] of string[5]=('nghìn','triệu','tỉ');

Var  strTemp,s:string;

countLevel,i:byte;

Function ReadNum(strNum:string):string;

Const strRN:array[2..9] of string[4]=('hai','ba','bốn','năm','sáu','bảy','tám','chín');

Var index:byte;

ch:char;

strRead:string;

Begin

strRead:='';

index:=1;

while strNum[index]=' ' do Inc(index);

repeat

ch:=strNum[index];

case ch of

'0':begin

if (index=1) and ((strNum[index+1]<>'0') or (strNum[index+2]<>'0')) then strRead:=strRead+'không ';

if (index=2) and (strNum[index+1]<>'0') then strRead:=strRead+'linh ';

if (index=3) and (strNum[index-1]=' ') then strRead:=strRead+'không '

end;

'1':if index=1 then strRead:=strRead+'một '

else if index=2 then strRead:=strRead+'mười '

else if strNum[index-1] in [' ','0','1'] then strRead:=strRead+'một '

else strRead:=strRead+'mốt ';

'5':if index<3 then strRead:=strRead+'năm '

else if not (strNum[index-1] in [' ','0']) then strRead:=strRead+'lăm '

else strRead:=strRead+'năm ';

else strRead:=strRead+strRN[Ord(ch)-48]+' ';

end;

if (index=2) and not (strNum[2] in ['0','1']) then strRead:=strRead+'mươi ';

if (index=1) and (strRead<>'') then strRead:=strRead+'trăm ';

Inc(index);

Until index=4;

ReadNum:=strRead;

end;

Begin

while (strNum[1]='0') and (Length(strNum)>1) do Delete(strNum,1,1);

while (Length(strNum) mod 3)<>0 do strNum:=' '+strNum;

countLevel:=(Length(strNum) div 3)-1;

s:='';

Repeat

strTemp:=ReadNum(Copy(strNum,1,3));

s:=s+strTemp;

Delete(strNum,1,3);

i:=countLevel mod 3;

if i>0 then

if strTemp<>'' then s:=s+levelNum[i]+' '

else

else if not (Copy(s,Length(s)-2,2)='tỉ') then

begin

i:=countLevel div 3;

while i>0 do

begin

s:=s+levelNum[3]+' ';

Dec(i);

end;

end;

Dec(countLevel);

Until strNum='';

s:=s+'đồng';

VND:=s;

end;


hainam4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com