fungsi terbilang dengan delphi
Saya dapat hasil serching d imbah google saya belum coba seh tpi coba az dulu...
unit U_NumToWord; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) ed_number: TEdit; Label1: TLabel; btn_ubah: TButton; Label2: TLabel; ed_word: TEdit; procedure btn_ubahClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} function Num2Word_Indonesian(dNumber: Extended): string; const aNum: array[1..9] of String[8] = ('satu', 'dua', 'tiga', 'empat', 'lima', 'enam', 'tujuh', 'delapan', 'sembilan'); aUnit: array[1..5] of String[7] = ('trilyun', 'milyar', 'juta', 'ribu', ''); var iCount, iDigit1, iDigit2, iDigit3: Integer; sNum2Str, s3Digit, sWord: string; begin Result := ''; if (dNumber=0) then Exit; sNum2Str:=Copy(Format('%18.2f', [dNumber]), 1, 15); for ICount:=1 to 5 do begin s3Digit:=Copy(sNum2Str, iCount*3-2, 3); if (StrToIntDef(s3Digit, 0)<>0) then begin sWord:=''; iDigit1:=StrToIntDef(Copy(s3Digit, 1, 1), 0); iDigit2:=StrToIntDef(Copy(s3Digit, 2, 1), 0); iDigit3:=StrToIntDef(Copy(s3Digit, 3, 1), 0); case iDigit1 of 2..9: sWord:=sWord+aNum[iDigit1]+' ratus '; 1: sWord:=sWord+'seratus '; end; { case } case iDigit2 of 2..9: sWord:=sWord+aNum[iDigit2]+' puluh '; 1: case iDigit3 of 2..9: sWord:=sWord+aNum[iDigit3]+' belas '; 1: sWord:=sWord+'sebelas '; 0: sWord:=sWord+'sepuluh '; end; { case } end; { case } if (iDigit2<>1) then case iDigit3 of 2..9: sWord:=sWord + aNum[iDigit3] + ' '; 1: if (iCount=4) and ((iDigit1+iDigit2)=0) then sWord:=sWord+'se' else sWord:=sWord+'satu '; end; Result:=Result+sWord+aUnit[iCount]+' '; end; end; while Result[Length(Result)]=' ' do SetLength(Result, Length(Result)-1); end; procedure TForm1.btn_ubahClick(Sender: TObject); var x: double; begin x:=strtoint(ed_number.Text); ed_word.Text:=Num2Word_Indonesian(x); end; end.
0 comments:
Post a Comment