PDA

View Full Version : نمایش اعداد به حروف



b_mohammadpoor
پنج شنبه 09 مرداد 1382, 11:42 صبح
کسی کامپوننت یا OCX داره که اعداد را به حروف نمایش بده :wink:

SyntaxCheck
پنج شنبه 09 مرداد 1382, 20:28 عصر
function AliHgethoroof(i:int64):string;
const v=' و ';
var
ok:boolean;
{___________________________________}
function yekan(y:byte):string;
begin
case y of
0:result:='';
1:result:='یک';
2:result:='دو';
3:result:='سه';
4:result:='چهار';
5:result:='پنج';
6:result:='شش';
7:result:='هفت';
8:result:='هشت';
9:result:='نه';
enD;
if result=''then ok:=false else ok:=true;
end;
{___________________________________}
function dahgan(y:byte):string;
begin
case y of
0:result:='';
1:result:='ده';
2:result:='بیست';
3:result:='سی';
4:result:='چهل';
5:result:='پنجاه';
6:result:='شصت';
7:result:='هفتاد';
8:result:='هشتاد';
9:result:='نود';
enD;
if result=''then ok:=false else ok:=true;
end;
{___________________________________}
function sadgan(y:byte):string;
begin
case y of
0:result:='';
1:result:='یکصد';
2:result:='دویست';
3:result:='سیصد';
4:result:='چهارصد';
5:result:='پانصد';
6:result:='ششصد';
7:result:='هفتصد';
8:result:='هشتصد';
9:result:='نهصد';
enD;
if result=''then ok:=false else ok:=true;
end;
{___________________________________}
function dah(y:byte):string;
begin
case y of
0:result:='';
10:result:='ده';
11:result:='یازده';
12:result:='دوازده';
13:result:='سیزده';
14:result:='چهارده';
15:result:='پانزده';
16:result:='شانزده';
17:result:='هفده';
18:result:='هجده';
19:result:='نوزده';
enD;
if result=''then ok:=false else ok:=true;
end;
{___________________________________}
function seragham(si:smallint):string;
begin
result:='';
result:=sadgan(si div 100);
if ok then result:=result+v;

if((si mod 100)div 10)<>1 then begin
result:=result+dahgan((si mod 100)div 10);
if ok then result:=result+v;
result:=result+yekan(si mod 10);
if not ok then result:=copy(result,1,length(result)-3);
End
else begin
result:=result+dah(si mod 100);
end;
if result='' then ok:=false else ok:=true;
end;
{___________________________________}
const
tr=' تریلیون';
mr=' میلیارد';
ml=' میلیون';
hz=' هزار';
begin
ok:=false;

result:=seragham(i div 1000000000000);
if ok then result:=result+tr+v;
result:=result+seragham((i mod 1000000000000)div 1000000000);
if ok then result:=result+mr+v;
result:=result+seragham((i mod 1000000000)div 1000000);
if ok then result:=result+ml+v;
result:=result+seragham((i mod 1000000)div 1000);
if ok then result:=result+hz+v;
result:=result+seragham(i mod 1000);
if not ok then result:=copy(result,1,length(result)-3);

if i=0 then result:='صفر';
end;

این کد رو سعی کردم طوری بنویسم که بعدا اگر نیاز به استفاده از اعداد بزرگتر شد امکان توسعه دادنش باشه.
پیروز باشید.