KASKUS

[ask] [PHP] koding konversi angka ke huruf

agan2 master php...

ada yang punya coding php mengkonfersi angka menjadi huruf..??

klo ada yang punya tolong d'sharekan donk gan...

nih gan ..
Code:

function TfrmMain.Terbilang(aNumber: String): String;
var S, S1 : String;
Q1, Q2 : String;
I, J : Integer;
begin
S := Trim(aNumber);
if (S = '') then
begin
S := '000';
end;
try StrToInt64(S);
except on EConvertError do
begin
ShowMessage('Harus diisi bilangan bulat.');
ActiveControl := edtJumlah;
Exit;
end;
end;
I := 0;
Q1 := '';
repeat if (Length(S) < 3) then
begin
S1 := StringOfChar('0', 3 - Length(S)) + S;
S := '';
end
else
begin
S1 := Copy(S, Length(S) - 2, 3);
S := Copy(S, 1, Length(S) - 3);
end;
Q2 := '';
for J := 1 to 3 do
begin
Q2 := Q2 + Pembilang[S1[J]];
if (Pembilang[S1[J]] <> '') then
begin
case J of
1 : begin
Q2 := Q2 + 'ratus ';
end;
2 : begin
Q2 := Q2 + 'puluh ';
end;
end;
end;
end;
Q2 := StringReplace(Q2, 'satu ratus', 'seratus', []);
Q2 := StringReplace(Q2, 'satu puluh', 'sepuluh', []);
Q2 := StringReplace(Q2, 'sepuluh satu', 'sebelas', []);
Q2 := StringReplace(Q2, 'sepuluh dua', 'dua belas', []);
Q2 := StringReplace(Q2, 'sepuluh tiga', 'tiga belas', []);
Q2 := StringReplace(Q2, 'sepuluh empat', 'empat belas', []);
Q2 := StringReplace(Q2, 'sepuluh lima', 'lima belas', []);
Q2 := StringReplace(Q2, 'sepuluh enam', 'enam belas', []);
Q2 := StringReplace(Q2, 'sepuluh tujuh', 'tujuh belas', []);
Q2 := StringReplace(Q2, 'sepuluh delapan', 'delapan belas', []);
Q2 := StringReplace(Q2, 'sepuluh sembilan', 'sembilan belas', []);
Inc(I);
if (Length(Q2) > 0) then
begin
case I of
1 : begin
Q2 := Q2 + 'rupiah.';
end;
2 : begin
Q2 := Q2 + 'ribu ';
if (Pos('satu ribu', Q2) = 1) then
begin
Q2 := StringReplace(Q2, 'satu ribu', 'seribu', []);
end;
end;
3 : begin
Q2 := Q2 + 'juta ';
end;
4 : begin
Q2 := Q2 + 'miliar ';
end;
5 : begin
Q2 := Q2 + 'triliun ';
end;
6 : begin
Q2 := Q2 + 'kuadriliun ';
end;
7 : begin
Q2 := Q2 + 'kuintiliun ';
end;
end;
end;
Q1 := Q2 + Q1;
until Length(S) = 0;
Result := Q1;
end;


tapi pake pascal .......................................................
Quote:Original Posted By gemini15
agan2 master php...

ada yang punya coding php mengkonfersi angka menjadi huruf..??

klo ada yang punya tolong d'sharekan donk gan...



https://github.com/pear/Numbers_Words
Quote:Original Posted By peyotpetot
nih gan ..
Code:

function TfrmMain.Terbilang(aNumber: String): String;
var S, S1 : String;
Q1, Q2 : String;
I, J : Integer;
begin
S := Trim(aNumber);
if (S = '') then
begin
S := '000';
end;
try StrToInt64(S);
except on EConvertError do
begin
ShowMessage('Harus diisi bilangan bulat.');
ActiveControl := edtJumlah;
Exit;
end;
end;
I := 0;
Q1 := '';
repeat if (Length(S) < 3) then
begin
S1 := StringOfChar('0', 3 - Length(S)) + S;
S := '';
end
else
begin
S1 := Copy(S, Length(S) - 2, 3);
S := Copy(S, 1, Length(S) - 3);
end;
Q2 := '';
for J := 1 to 3 do
begin
Q2 := Q2 + Pembilang[S1[J]];
if (Pembilang[S1[J]] <> '') then
begin
case J of
1 : begin
Q2 := Q2 + 'ratus ';
end;
2 : begin
Q2 := Q2 + 'puluh ';
end;
end;
end;
end;
Q2 := StringReplace(Q2, 'satu ratus', 'seratus', []);
Q2 := StringReplace(Q2, 'satu puluh', 'sepuluh', []);
Q2 := StringReplace(Q2, 'sepuluh satu', 'sebelas', []);
Q2 := StringReplace(Q2, 'sepuluh dua', 'dua belas', []);
Q2 := StringReplace(Q2, 'sepuluh tiga', 'tiga belas', []);
Q2 := StringReplace(Q2, 'sepuluh empat', 'empat belas', []);
Q2 := StringReplace(Q2, 'sepuluh lima', 'lima belas', []);
Q2 := StringReplace(Q2, 'sepuluh enam', 'enam belas', []);
Q2 := StringReplace(Q2, 'sepuluh tujuh', 'tujuh belas', []);
Q2 := StringReplace(Q2, 'sepuluh delapan', 'delapan belas', []);
Q2 := StringReplace(Q2, 'sepuluh sembilan', 'sembilan belas', []);
Inc(I);
if (Length(Q2) > 0) then
begin
case I of
1 : begin
Q2 := Q2 + 'rupiah.';
end;
2 : begin
Q2 := Q2 + 'ribu ';
if (Pos('satu ribu', Q2) = 1) then
begin
Q2 := StringReplace(Q2, 'satu ribu', 'seribu', []);
end;
end;
3 : begin
Q2 := Q2 + 'juta ';
end;
4 : begin
Q2 := Q2 + 'miliar ';
end;
5 : begin
Q2 := Q2 + 'triliun ';
end;
6 : begin
Q2 := Q2 + 'kuadriliun ';
end;
7 : begin
Q2 := Q2 + 'kuintiliun ';
end;
end;
end;
Q1 := Q2 + Q1;
until Length(S) = 0;
Result := Q1;
end;


tapi pake pascal .......................................................



anee lom ngerti pascal gan...

orang ane ngertinya php.., heehehehehehe...

<?php

function AngkaToHuruf($val)
{



$konversi = array(1=>'A',2=>'B',3=>'C',4=>'D',5=>'E');
$nilai = str_split($val);
$hasil = '';
foreach ($nilai as $value)
{
$hasil .= $konversi[$value]."";
}
return $hasil;
}

$var = 1234554321;
echo AngkatoHuruf($var);
?>
Kayak gitu bukan, jika script diatas dijalankan maka hasilnya= ABCDEEDCBA
Quote:Original Posted By gemini15

anee lom ngerti pascal gan...

orang ane ngertinya php.., heehehehehehe...



Sama gan ... gw juga ga ngerti php ..
Quote:Original Posted By peyotpetot
nih gan ..
Code:

function TfrmMain.Terbilang(aNumber: String): String;
var S, S1 : String;
Q1, Q2 : String;
I, J : Integer;
begin
S := Trim(aNumber);
if (S = ') then
begin
S := '000';
end;
try StrToInt64(S);
except on EConvertError do
begin
ShowMessage('Harus diisi bilangan bulat.');
ActiveControl := edtJumlah;
Exit;
end;
end;
I := 0;
Q1 := ';
repeat if (Length(S) < 3) then
begin
S1 := StringOfChar('0', 3 - Length(S)) + S;
S := ';
end
else
begin
S1 := Copy(S, Length(S) - 2, 3);
S := Copy(S, 1, Length(S) - 3);
end;
Q2 := ';
for J := 1 to 3 do
begin
Q2 := Q2 + Pembilang[S1[J]];
if (Pembilang[S1[J]] <> ') then
begin
case J of
1 : begin
Q2 := Q2 + 'ratus ';
end;
2 : begin
Q2 := Q2 + 'puluh ';
end;
end;
end;
end;
Q2 := StringReplace(Q2, 'satu ratus', 'seratus', []);
Q2 := StringReplace(Q2, 'satu puluh', 'sepuluh', []);
Q2 := StringReplace(Q2, 'sepuluh satu', 'sebelas', []);
Q2 := StringReplace(Q2, 'sepuluh dua', 'dua belas', []);
Q2 := StringReplace(Q2, 'sepuluh tiga', 'tiga belas', []);
Q2 := StringReplace(Q2, 'sepuluh empat', 'empat belas', []);
Q2 := StringReplace(Q2, 'sepuluh lima', 'lima belas', []);
Q2 := StringReplace(Q2, 'sepuluh enam', 'enam belas', []);
Q2 := StringReplace(Q2, 'sepuluh tujuh', 'tujuh belas', []);
Q2 := StringReplace(Q2, 'sepuluh delapan', 'delapan belas', []);
Q2 := StringReplace(Q2, 'sepuluh sembilan', 'sembilan belas', []);
Inc(I);
if (Length(Q2) > 0) then
begin
case I of
1 : begin
Q2 := Q2 + 'rupiah.';
end;
2 : begin
Q2 := Q2 + 'ribu ';
if (Pos('satu ribu', Q2) = 1) then
begin
Q2 := StringReplace(Q2, 'satu ribu', 'seribu', []);
end;
end;
3 : begin
Q2 := Q2 + 'juta ';
end;
4 : begin
Q2 := Q2 + 'miliar ';
end;
5 : begin
Q2 := Q2 + 'triliun ';
end;
6 : begin
Q2 := Q2 + 'kuadriliun ';
end;
7 : begin
Q2 := Q2 + 'kuintiliun ';
end;
end;
end;
Q1 := Q2 + Q1;
until Length(S) = 0;
Result := Q1;
end;


tapi pake pascal .......................................................
ane jg perlu kodingan ini
Quote:Original Posted By herloct


https://github.com/pear/Numbers_Words

Ini udah dikasih sama om herloct. Jangan alasan lagi ya