在一个EDIT中任意输入一个价格,
  如:输入——  输出(自动转化)
      123——123.00
     123.12——123.12
     123.EF报错

解决方案 »

  1.   

    这个啊!
    其实你可以在输入的时候限制的//-------------------------------------------------------------------
    // 功能:限制TEdit内输入的数字格式
    //时间:2004年5月28日
    //作者:Sunny
    //-------------------------------------------------------------------procedure TEditControl(Sender:TObject;Key: Word;Shift: TShiftState;FLength:integer;BLength:integer);
    var
      TmpStr:string;
    begin
      TmpStr:='';
      with Sender as TEDIT do
      begin
        ReadOnly:=True;
        if (Key in [48..57,96..105]) then
          TmpStr:= Copy(Text,1,SelStart)+inttostr((Key mod 48))+Copy(Text,SelStart+1,Length(Text))+' ';
        if (Key in [8,46]) then
          TmpStr:= Copy(Text,1,SelStart-1)+Copy(Text,SelStart+1,Length(Text))+' ';
        if ((Key in [109,189]) and (Pos('-',Text)=0) and (SelStart=0)) then
          TmpStr:=Copy(Text,1,SelStart)+'-'+Copy(Text,SelStart+1,Length(Text))+' ';
        if ((Key in [190,110]) and (Pos('.',Text)=0) and (SelStart<>Pos('-',Text)-1)) then
          TmpStr:= Copy(Text,1,SelStart)+'.'+Copy(Text,SelStart+1,Length(Text))+' ';
        if Pos(' ',TmpStr)>0 then
        begin
          TmpStr:=Copy(TmpStr,1,Length(TmpStr)-1);
          TmpStr:=StringReplace(TmpStr,'-','',[rfReplaceAll]);
          if Pos('.',TmpStr)=0 then TmpStr:=TmpStr+'.';
          TmpStr:=StringReplace(Trim(StringReplace(TmpStr,'0',' ',[rfReplaceAll])),' ','0',[rfReplaceAll]);
          if ((Pos('.',TmpStr)-1<=FLength) and (Length(TmpStr)-Pos('.',TmpStr)<=BLength)) then
            ReadOnly:=False;
        end;
      end;
    end;这样你的输入格式就完全被限制住了 接着转换的时候就直接写strToFloat
      

  2.   

    同意
    procedure TfrmAddMoney.edtMoneyKeyPress(Sender: TObject; var Key: Char);
    begin  if Pos(Key,'1234567890.') = 0 then begin
        Key := Chr(0);
        ShowMessage('不能输入非数字的字符!');
      end;
    end;
      

  3.   

    try
      StrToFloat;
    except
      ShowMessage('输入错误');
    end;
      

  4.   

    procedure InputCtr1(var Key : char);
    begin
      if not (Key in ['0'..'9',',','*','.',' ',#22,#3,#24,#26,#13,#27,#8]) then
      begin
        Key := #0;
       // showmessage('请输入整数或小数!');
        exit;
      end;
    end; 在keypress  中加入这个过程
      

  5.   

    procedure TForm1.Edit1Exit(Sender: TObject);
    begin
        Edit1.Text:=FormatFloat('0.00',StrToFloat(Edit1.Text));
    end;
      

  6.   

    Edit1.Text:=FormatFloat('0.00',StrToFloat(Edit1.Text));
    再限制不能为字母
      

  7.   

    try
    Edit1.Text:=FormatFloat('0.00',StrToFloat(Edit1.Text));
    except
    showmessage('请输入整数或小数!');
    end;
    可不可以??
      

  8.   

    Edit1.Text:=FormatFloat('0.00',StrToFloat(Edit1.Text));