Mega Code Archive

 
Categories / Delphi / Examples
 

Sayıyı yazıya çevirme, basit çözüm

//Gazili Kartaldan, güzel bir çözüm unit .....; interface uses sysutils; const bir:Array [0..9] of String[10]=('','Bir','İki','Üç','Dört','Beş','Altı','Yedi','Sekiz','Dokuz'); onlar:Array [0..9] of String[10]=('','On','Yirmi','Otuz','Kırk','Elli','Altmış','Yetmiş','Seksen','Doksan'); function yaziyla(Sayi:Double):String; function uclu(gelen:string):string; implementation function uclu(gelen:string):string; var b1,b2,b3:string; p:integer; begin b1:=bir[strtoint(copy(gelen,3,1))]; b2:=onlar[strtoint(copy(gelen,2,1))]; p:=strtoint(copy(gelen,1,1)); if p>1 then b3:=bir[strtoint(copy(gelen,1,1))]+ 'Yüz'; if p=1 then b3:='Yüz'; if p<1 then b3:=''; uclu:=b3+b2+b1; end; function yaziyla(Sayi:Double):String; var sonuc,sonuc1,sonuc2,sonuc3,sonuc4,s:string; u:integer; v:integer; begin s:='000000000000000'+ FloatToStr(Sayi); s:=copy(s,length(s)-14,15); if Sayi>0 then begin sonuc:=uclu(copy(s,13,3)); if uclu(copy(s,10,3))<>'' then begin if (copy(s,12,1)='1') and (copy(s,11,1)='0') and (copy(s,10,1)='0') then begin sonuc1:='Bin'; end else begin sonuc1:=uclu(copy(s,10,3))+'Bin'; end;//else-if end;//if if uclu(copy(s,7,3))<>'' then sonuc2:=uclu(copy(s,7,3))+' '+'Milyon'; if uclu(copy(s,4,3))<>'' then sonuc3:=uclu(copy(s,4,3))+' '+'Milyar'; if uclu(copy(s,1,3))<>'' then sonuc4:=uclu(copy(s,1,3))+' '+'Trilyon'; end; result:=''; if sonuc4<>'' then result:=result+sonuc4+','; if sonuc3<>'' then result:=result+sonuc3+','; if sonuc2<>'' then result:=result+sonuc2+','; if sonuc1<>'' then result:=result+sonuc1+','; if sonuc<>'' then result:=result+sonuc; if result='' then result:='Sıfır'; end; end.