Arsip: Konversi Rupiah ke Terbilang


by hasan_plg in Articles more 13 years ago 3426
berikut merupakan kode untuk melakukan konversi Rupiah ke Terbilang
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;
Syntax Highlighted with https://pascal-id.org/syntax



Anda boleh memakai tipe Numerik maupun String didalam Fungsi konversi ini.
Contoh 1: RpToStr( 1350 ); //Tipe Numerik
Contoh 2: RpToStr( '1350' ); //Tipe String
Terbilang : Seribu Tiga Ratus Lima Puluh Rupiah

Semoga bermanfaat bagi fans DELPHI-ID.ORG
Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com