25 October 2009

fungsi terbilang dengan delphi


  1. unit U_NumToWord;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  5. StdCtrls;
  6. type
  7. TForm1 = class(TForm)
  8. ed_number: TEdit;
  9. Label1: TLabel;
  10. btn_ubah: TButton;
  11. Label2: TLabel;
  12. ed_word: TEdit;
  13. procedure btn_ubahClick(Sender: TObject);
  14. private
  15. { Private declarations }
  16. public
  17. { Public declarations }
  18. end;
  19. var
  20. Form1: TForm1;
  21. implementation
  22. {$R *.DFM}
  23. function Num2Word_Indonesian(dNumber: Extended): string;
  24. const
  25. aNum: array[1..9] of String[8] = ('satu', 'dua', 'tiga', 'empat', 'lima', 'enam', 'tujuh', 'delapan', 'sembilan');
  26. aUnit: array[1..5] of String[7] = ('trilyun', 'milyar', 'juta', 'ribu', '');
  27. var
  28. iCount, iDigit1, iDigit2, iDigit3: Integer;
  29. sNum2Str, s3Digit, sWord: string;
  30. begin
  31. Result := '';
  32. if (dNumber=0) then Exit;
  33. sNum2Str:=Copy(Format('%18.2f', [dNumber]), 1, 15);
  34. for ICount:=1 to 5 do
  35. begin
  36. s3Digit:=Copy(sNum2Str, iCount*3-2, 3);
  37. if (StrToIntDef(s3Digit, 0)<>0) then
  38. begin
  39. sWord:='';
  40. iDigit1:=StrToIntDef(Copy(s3Digit, 1, 1), 0);
  41. iDigit2:=StrToIntDef(Copy(s3Digit, 2, 1), 0);
  42. iDigit3:=StrToIntDef(Copy(s3Digit, 3, 1), 0);
  43. case iDigit1 of
  44. 2..9: sWord:=sWord+aNum[iDigit1]+' ratus ';
  45. 1: sWord:=sWord+'seratus ';
  46. end; { case }
  47. case iDigit2 of
  48. 2..9: sWord:=sWord+aNum[iDigit2]+' puluh ';
  49. 1: case iDigit3 of
  50. 2..9: sWord:=sWord+aNum[iDigit3]+' belas ';
  51. 1: sWord:=sWord+'sebelas ';
  52. 0: sWord:=sWord+'sepuluh ';
  53. end; { case }
  54. end; { case }
  55. if (iDigit2<>1) then
  56. case iDigit3 of
  57. 2..9: sWord:=sWord + aNum[iDigit3] + ' ';
  58. 1: if (iCount=4) and ((iDigit1+iDigit2)=0) then
  59. sWord:=sWord+'se'
  60. else
  61. sWord:=sWord+'satu ';
  62. end;
  63. Result:=Result+sWord+aUnit[iCount]+' ';
  64. end;
  65. end;
  66. while Result[Length(Result)]=' ' do
  67. SetLength(Result, Length(Result)-1);
  68. end;
  69. procedure TForm1.btn_ubahClick(Sender: TObject);
  70. var
  71. x: double;
  72. begin
  73. x:=strtoint(ed_number.Text);
  74. ed_word.Text:=Num2Word_Indonesian(x);
  75. end;
  76. end.
Saya dapat hasil serching d imbah google saya belum coba seh tpi coba az dulu...


Artikel Terkait:

0 comments:

Post a Comment

Tolong klik Iklan Sponsor...para pengunjung....

free counters

Sponsor

Get paid To Promote at any Location

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP