uses Math; RoundTo() for Delphi6Int(X * 1000) /1000

解决方案 »

  1.   

    1、
    char s[32];
    f=3.123467;
    sprintf(s,"%0.3f",f);   //3可以改为其他2、f=3.123467;
       f=((long)(f*1000.0+0.5))/1000.0;  //四舍五入
       f=((long)(f*1000.0))/1000.0;   
      

  2.   

    str := Format('%5.3f',3.123467)
      

  3.   

    str := Format('%5.3f',3.123467),好像有错,不能正确运行,应该是:
    str := Format('%5.3f',[3.123467]),这样做就可以将变量格式化了:
    myvalue:=3.123467;
    str:=Format('%5.3f',[myvalue]);
    myvalue:=StrToFloat(str);
      

  4.   

    function Strsimplify(const a:string;const num:integer):string;
    var
    i:integer;
    begin
         i:=pos('.',a);
         if i=0 then
            result:=a
         else
            begin
                    if num=0 then
                       result:=copy(a,1,i-1)
                    else
                       result:=copy(a,1,i+num)
            end;
    end;
    调用上面函数
    比如将a=3.1234567截取小数点后4位,可以如下调用
    b:=Strsimplify(inttostr(a),4);
      

  5.   

    function Strsimplify(const a:string;const num:integer):string;
    var
    i:integer;
    begin
         i:=pos('.',a);
         if i=0 then
            result:=a
         else
            begin
                    if num=0 then
                       result:=copy(a,1,i-1)
                    else
                       result:=copy(a,1,i+num)
            end;
    end;
    调用上面函数
    比如将a=3.1234567截取小数点后4位,可以如下调用
    b:=Strsimplify(inttostr(a),4);
      

  6.   

    楼上的函数最后有点小问题:a是Float,所以要用FloatToStr才行,
    可能是忽略了,呵呵