KONVERSI ANGKA KE TERBILANG

19.18
Source berikut merupakan source DELPHI yang berguna untuk konversi angka ke terbilang. Sourcenya sebagai berikut :
function Right( Str: String; Len: Integer ): String;
begin
Result := Copy(St, (Length(St)+1)-Len, Len);
end;

function Left( Str: String; Len: Integer ): String;
begin
Result := Copy(St, 1, Len);
end;

function RpToStr( Rp: Double ): String; overload;
begin
Result := RpToStr( FloatToStr(Rp) );
end;

function RpToStr( Rp: String ): String; overload;
var cRp, sRp: String;
var nRp, nRp1, nRp2: Integer;
var aRp1 : array[0..9] of String = (\"\", \"Satu \", \"Dua \", \"Tiga \", \"Empat \", \"Lima \", \"Enam \", \"Tujuh \", \"Delapan \", \"Sembilan \");
var aRp2 : array[0..5] of String = (\"\", \"Ribu \", \"Juta \", \"Milyar \", \"Triliun \");
var aRp3 : Array[0..5] of String;

nRp1 := 0;
cRp := Trim( Rp );

while length(cRp) > 0 do begin
aRp3[nRp1] := Right(cRp, 3);
cRp := Left(cRp, length(cRp)-3);
inc(nRp1);
end;
nRp2 := nRp1;

Result := '';
while nRp1 >= 0 do begin
cRp := '';
sRp := aRp3[nRp1];

if (length(sRp) = 3) then begin
nRp := StrToInt( Left(sRp,1) )
if (nRp = 1) then begin
cRp := \"Seratus \";
end else if (nRp <> 0) then begin
cRp := aRp1[ nRp ] + \"Ratus \";
end;
sRp := Right(sRp,len(sRp)-1);
end;

if (length(sRp) = 2) then begin
nRp := StrToInt( Left(sRp,1) );
if (nRp = 1) then begin
nRp := StrToInt( Right(sRp,1) );
if (nRp = 0) then begin
cRp := cRp + \"Sepuluh \";
end else if (nRp = 1) then begin
cRp := cRp + \"Sebelas \";
end else begin
cRp := cRp + aRp1[ nRp ] + \"Belas \";
end;
sRp := '';
end else begin
cRp := cRp + aRp1[ nRp ] + \"Puluh \";
end;
sRp := Right(sRp,length(sRp)-1)
end;

if (length(sRp) = 1) then begin
nRp := StrToInt( sRp );
cRp := cRp + aRp1[ nRp ];
end;

Result := Result + cRp + aRp2[nRp2];
dec(nRp1);
dec(nRp2);
end;

if Trim(Result) <> '' then Result := Result + 'Rupiah';
end;

Sumber http://www.delphi-id.org

Artikel Terkait

Previous
Next Post »