type tFormatUang=Record
Text:String;
SelStart:Integer;
end;
function FormatUang(input:string):tFormatUang;
var
sRupiah: string;
min,i,c:word; dec:boolean;
begin
sRupiah:='';
c:=1;
dec:=false;
if length(input)>0 then
begin
if input[1]='-' then min:=2 else min:=1;
for i:=length(input) downto min do
if input[i]='.' then dec:=true;
for i:=length(input) downto min do
begin
if input[i] in ['0'..'9','.','-'] then
begin
if input[i]='.' then
begin
dec:=false;
c:=0;
end;
if c=4 then
begin
if dec=false then sRupiah:=input[i]+','+sRupiah;
c:=1;
end else sRupiah:=input[i]+sRupiah;
if dec=false then inc(c);
end;
end;
if input[1]='-' then sRupiah:='-'+sRupiah;
end;
FormatUang.Text := sRupiah;
FormatUang.SelStart := length(sRupiah);
end;
Contoh :
procedure TForm1.Edit1Change(Sender: TObject);
begin
Edit1.Text:=FormatUang(Edit1.Text).Text;
Edit1.SelStart:=FormatUang(Edit1.Text).SelStart;
end;
0 comments :
Posting Komentar
Terima kasih atas kunjungan dan komentarnya