如果在 TEdit 中处理,可以在 OnExit 事件中如下进行:
procedure TForm1.Edit1Exit(Sender: TObject);
var
x:integer;
y:string;
begin
y:=Edit1.text;
x:=pos('.',y);
if x<0 then
exit;
if (x+2<length) then
Edit1.text:=copy(y,1,x+2);
end;
procedure TForm1.Edit1Exit(Sender: TObject);
var
x:integer;
y:string;
begin
y:=Edit1.text;
x:=pos('.',y);
if x<=0 then
exit;
//这里
if (x+2<length) then
Edit1.text:=copy(y,1,x+2);
end;