temp1:=strtofloat(edit1.text);
temp2:=strtofloat(edit2.text);
try
  edit3.text:=floattostr(temp1/temp2);
 except
 end;

解决方案 »

  1.   

    try
      Edit3.Text := FloatToStr(StrToFloat(Edit1.Text)/StrToFloat(Edit2.Text));
    except
      ShowMessage('输入错误');
    end;
      

  2.   

    在ONExit里写;
    edit1
      if Edit2.Text = '' then
      begin
       try
        Edit3.Text := FloatToStr(StrToFloat(Edit1.Text)/StrToFloat(Edit2.Text));
       except
         exit;
       end
        
      end;edit2
    edit
      if Edit2.Text = '' then
      begin
       try
        Edit3.Text := FloatToStr(StrToFloat(Edit1.Text)/StrToFloat(Edit2.Text));
       except
         Application.Message('对不起,请您检查输入格式是否有错','错误提示',MB_OK + MB_ICONINFORMATION);
         exit;
       end
        
      end;onpress
    if Not (Key in ('0'..'9','.',#8,#46)) then
       Key := #0;
      

  3.   

    ok,thanks!请问如何将结果四舍五入保留到整数位?
      

  4.   

    上面都太复杂,我在计算工资的时候,将公式保存起来,然后用一个edit来调用公式,比如(2*3+5)/100,利用msscrip.ocx控件可以直接计算出结果. 注:msscrip.ocx是windows自己带的运算组件.
      

  5.   

    to:jasonbecker() 四舍五入可以用两种方法实现:
    1:round(n)
    2:format('%5.2f',n)   其中'%5.2f'可以跟据需要调整具体可以参见delphi的帮助
      

  6.   

    四舍五入用round
    trunc是取整
      

  7.   

    try
      Edit3.Text := Int64ToStr(Round(StrToFloat(Edit1.Text)/StrToFloat(Edit2.Text)));
    except
      ShowMessage('您的输入有误');
    end;
      

  8.   

    try
      Edit3.Text := FloatToStr(Round(StrToFloat(Edit1.Text)*100/StrToFloat(Edit2.Text))/100);
    except
      ShowMessage('您的输入有误');
    end;