Mega Code Archive

 
Categories / Delphi / Examples
 

Sayıyı yazıya çevirme, [daha kısa, daha hızlı ve güvenilir ]

function Cevir(Val : extended) : String; const hanex : array[0..2, '0'..'9'] of String = ( ('', 'Bir ', 'İki ', 'Üç ', 'Dört ', 'Beş ', 'Altı ', 'Yedi ', 'Sekiz ', 'Dokuz '), ('', 'On ', 'Yirmi ', 'Otuz ', 'Kırk ', 'Elli ', 'Atmış ', 'Yetmiş ', 'Seksen ', 'Doksan '), ('', 'Yüz ', 'İki Yüz ', 'Üç Yüz ', 'Dört Yüz ', 'Beş Yüz ', 'Altı Yüz ', 'Yedi Yüz ', 'Sekiz Yüz ', 'Dokuz Yüz ')); katx : array[0..5] of String = ('', 'Bin ', 'Milyon ', 'Milyar ', 'Trilyon ', 'Katrilyon '); var Kat : Integer; function _Cevir(sy : String) : String; var lsy, hn : Integer; begin Result := ''; if sy = '' then Exit; if (sy = '1') and (kat = 1) then begin Result := 'Bin'; Exit; end; hn := 0; lsy := length(sy); while (hn < 3) and (hn < lsy) do begin Result := hanex[hn, sy[lsy - hn]] + Result; Inc(hn); end; Result := Result + katx[kat]; Inc(kat); if lsy > 3 then Result := _Cevir(copy(sy, 1, lsy - 3)) + Result; end; begin Result := ''; kat := 0; Result := _Cevir(formatFloat('##0', int(Val))); end;