以下是的代码。出现是比如说edit1的值是12.22,edit2的值是12.21,而求出得到的值是
也就是说凡是小于0.01的值相加减时就会出现不相等错误,这是怎么会事求各位大侠帮忙。Var Str1,str2,str3:Double;
begin
Str1:=strtofloat(edit1.text);
str2:=strTofloat(edit2.text);
str3:=floatTostr(Str1-str2);
edit3.text:=str3;
end;
end.
以下是所取的值,
edit1=12.21;
edit2=12.20;
edit3=00000094....

解决方案 »

  1.   

    DOUBLE类型相减的值,小于一个比较小的数,就认为这两个相减的数相等。
    例如A-B=0.0000001,那么可以认为A=B
      

  2.   

    建议使用精度更高的数据如decimal,它表示精度高,但是范围比single还小
      

  3.   

    floatTostr转换的数据有限吧,你增大点试试.
      

  4.   

    str3:=floatTostr(Str1-str2);
    请问:你这句话要得嘛???
    你的Str3是Double型的怎么能转换成String型?????
    你的Delphi是哪个版本的??编译的时候能通过??我用的Delphi7就通不过!!
      

  5.   

    Var Str1,str2,str3:Extended;
    这样答案就是0.01
    只有把Str1,Str2,Str3设为Extended才行!
      

  6.   

    sweetch(龙の吻ж龙文) 的对,没必要非得用DUBLE。
      

  7.   

    借楼主宝地一用,散分:
    http://community.csdn.net/Expert/topic/3607/3607806.xml?temp=.9890863
      

  8.   

    strtofloat(stringreplace(label12.Caption,',','',[rfreplaceall]));
      

  9.   

    round(bcsfje*100)/100 = round(sqqk*100)/100