Terbilang dalam bahasa Inggris – Bagian 2

by A Rahman

Setelah aku menulis tentang “Terbilang dalam Bahasa Inggris” disini, ternyata tiap hari ada saja orang yang searching dan mampir di blog ini untuk mencari solusi tentang terbilang dalam bahasa Inggris.

Nah ini aku tambahin yang ada coding-nya.

Pertama dalam bahasa VBA yang bisa diperoleh disini, disebut currencytowords.

Kedua, daripada pusing-pusing nyari pada nggak sesuai dengan seleraku, maka aku konversi aja program lama dalam bahasa Clipper yang kupunya dari buku “Using Clipper, Special Edition” karangan Edward Tiley.  Dikonversi ke dalam Delphi dalam bentuk fungsi jadi begini :

// This function produces English words for monetary amounts.
// It is written for U.S. Dollars, but can be modified for
// any decimal based currency. Value must be under 10 million.

Function NTOC(nAmount:double):string;
var
cAmtStr, cRetVal:string;
aSingle: array of String;
aDecade: array of String;
aTeens : array of String;
nCents, nOnes, nTens, nHund : integer;
nThousand, nTenThousand, nHundThousand : integer;
nMillion,nTenMillion,nHundMillion : integer;
nBillion,nTenBillion : integer;
nSisa : double ;
begin
SetLength(aSingle,9);
aSingle[0] := ‘one ‘;
aSingle[1] := ‘two ‘;
aSingle[2] := ‘three ‘;
aSingle[3] := ‘four ‘;
aSingle[4] := ‘five ‘;
aSingle[5] := ‘six ‘;
aSingle[6] := ‘seven ‘;
aSingle[7] := ‘eight ‘;
aSingle[8] := ‘nine ‘;

SetLength(aDecade,9);
aDecade[0] := ‘ten ‘;
aDecade[1] := ‘twenty ‘;
aDecade[2] := ‘thirty ‘;
aDecade[3] := ‘forty ‘;
aDecade[4] := ‘fifty ‘;
aDecade[5] := ‘sixty ‘;
aDecade[6] := ‘seventy ‘;
aDecade[7] := ‘eighty ‘;
aDecade[8] := ‘ninety ‘;

SetLength(aTeens,10);
aTeens[0] := ‘ten ‘;
aTeens[1] := ‘eleven ‘;
aTeens[2] := ‘twelve ‘;
aTeens[3] := ‘thirteen ‘;
aTeens[4] := ‘fourteen ‘;
aTeens[5] := ‘fifteen ‘;
aTeens[6] := ‘sixteen ‘;
aTeens[7] := ‘seventeen ‘;
aTeens[8] := ‘eighteen ‘;
aTeens[9]:= ‘nineteen ‘;

//99 999 999 9 9 9. 99
//12 345 678 9 10 11
IF nAmount > 99999999999.99 then

begin
result := ‘******************’;
exit;
end;

cAmtStr := isinolstring(floattostr(nAmount*100),13);

nCents := strtointdef(Copy(cAmtStr,12,2),0);
nOnes := strtointdef(Copy(cAmtStr,11,1),0);
nTens := strtointdef(Copy(cAmtStr,10,1),0);
nHund := strtointdef(Copy(cAmtStr, 9,1),0) ;
nThousand := strtointdef(Copy(cAmtStr, 8,1),0) ;
nTenThousand := strtointdef(Copy(cAmtStr, 7,1),0) ;
nHundThousand := strtointdef(Copy(cAmtStr, 6,1),0) ;
nMillion := strtointdef(Copy(cAmtStr, 5,1),0) ;
nTenMillion := strtointdef(Copy(cAmtStr, 4,1),0) ;
nHundMillion := strtointdef(Copy(cAmtStr, 3,1),0) ;
nBillion := strtointdef(Copy(cAmtStr, 2,1),0) ;
nTenBillion := strtointdef(Copy(cAmtStr, 1,1),0) ;

cRetval:=”;

//—————————————————
if nTenBillion<>0 then
begin
if nTenBillion<2 then cRetVal := cRetVal + aTeens[nBillion]
else cRetVal := cRetVal + aDecade[nTenBillion-1];
end;

if ((nBillion<>0) and (nTenBillion<>1))
then cRetVal := cRetVal + aSingle[nBillion-1];

if nTenBillion+nBillion<>0 then cRetVal := cRetVal + ‘billion ‘;
//—————————————————
if nHundMillion<>0 then cRetVal := cRetVal + aSingle[nHundMillion-1]+’hundred ‘;

if nTenMillion<>0 then
begin
if nTenMillion<2 then cRetVal := cRetVal + aTeens[nMillion]
else cRetVal := cRetVal + aDecade[nTenMillion-1];
end;

if ((nMillion<>0) and (nTenMillion<>1))
then cRetVal := cRetVal + aSingle[nMillion-1];

if nHundMillion+nTenMillion+nMillion<>0 then cRetVal := cRetVal + ‘million ‘;
//—————————————————
if nHundThousand<>0 then cRetVal := cRetVal + aSingle[nHundThousand-1]+’hundred ‘;

if nTenThousand<>0 then
begin
if nTenThousand<2 then cRetVal := cRetVal + aTeens[nThousand]
else cRetVal := cRetVal + aDecade[nTenThousand-1];
end;

if ((nThousand<>0) and (nTenThousand<>1))
then cRetVal := cRetVal + aSingle[nThousand-1];

if nHundThousand+nTenThousand+nThousand<>0 then cRetVal := cRetVal + ‘thousand ‘;
//—————————————————
if nHund<>0 then cRetVal := cRetVal + aSingle[nHund-1]+’hundred ‘;

if nTens<>0 then
begin
if nTens<2 then cRetVal := cRetVal + aTeens[nOnes]
else cRetVal := cRetVal + aDecade[nTens-1];
end;

if ((nOnes<>0) and (nTens<>1))
then cRetVal := cRetVal + aSingle[nOnes-1];
//—————————————————
nSisa := trunc((nAmount-trunc(nAmount))*100);
if nSisa>0 then cRetVal := cRetVal + ‘and ‘+floattostr(nSisa)+’/100’;

result := cRetVal;
end;

Cuma disini untuk nilai sen aku tulis angkanya /100 di akhir kalimat terbilangnya.

O iya, disitu ada fungsi Isinolstring.  Isi fungsinya adalah :

function IsiNolString(Angka:string;nPjg:Integer): string;
var st:string;
begin
st:=trimright(trimleft(Angka));
result:=st;
if length(st)>=nPjg then result:=copy(st,1,nPjg)
else Result := replicate(‘0’,nPjg-length(st))+st;
end;

function Replicate(Ch: Char; Len: Integer): string;
var i:integer;
begin
result:=”;
for i:=0 to len-1 do
result:=result+Ch;
end;

Semoga bermanfaat

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s