float可不可以转换为integer??how??
或者delphi取整函数有没有?

解决方案 »

  1.   

    Returns the value of X rounded to the nearest whole number.UnitSystemCategoryarithmetic routinesDelphi syntax:function Round(X: Extended): Int64;DescriptionIn Delphi, the Round function rounds a real-type value to an integer-type value.X is a real-type expression. Round returns an Int64 value that is the value of X rounded to the nearest whole number. If X is exactly halfway between two whole numbers, the result is always the even number. This method of rounding is often called "Banker抯 Rounding".If the rounded value of X is not within the Int64 range, a runtime error is generated, which can be handled using the EInvalidOp exception.Note: The behavior of Round can be affected by the Set8087CW procedure or SetRoundMode function.
      

  2.   

    var   S, T: string;begin   Str(1.4:2:1, T);
       S := T + ' rounds to ' + IntToStr(Round(1.4)) + #13#10;
       Str(1.5:2:1, T);
       S := S + T + ' rounds to ' + IntToStr(Round(1.5)) + #13#10;
       Str(-1.4:2:1, T);
       S := S + T + ' rounds to ' + IntToStr(Round(-1.4)) + #13#10;
       Str(-1.5:2:1, T);
       S := S + T + ' rounds to ' + IntToStr(Round(-1.5));
       MessageDlg(S, mtInformation, [mbOk], 0, mbOk);
    end;
      

  3.   

    Truncates a real number to an integer.UnitSystemCategoryarithmetic routinesDelphi syntax:function Trunc(X: Extended): Int64;DescriptionIn Delphi code, the Trunc function truncates a real-type value to an integer-type value. X is a real-type expression. Trunc returns an Int64 value that is the value of X rounded toward zero.If the truncated value of X is not within the Int64 range, an EInvalidOp exception is raised.
      

  4.   

    var   S, T: string;
    begin
       Str(1.4:2:1, T);
       S := T + ' Truncs to ' + IntToStr(Trunc(1.4)) + #13#10;
       Str(1.5:2:1, T);
       S := S + T + ' Truncs to ' + IntToStr(Trunc(1.5)) + #13#10;
       Str(-1.4:2:1, T);
       S := S + T + ' Truncs to ' + IntToStr(Trunc(-1.4)) + #13#10;
       Str(-1.5:2:1, T);
       S := S + T + ' Truncs to ' + IntToStr(Trunc(-1.5));
       MessageDlg(S, mtInformation, [mbOk], 0, mbOk);
    end;
      

  5.   

    showmessage(inttostr(round(7.89)));
    showmessage(inttostr(trunc(7.89)));
      

  6.   

    trunc 就是传说中的取整函数,^_^
      

  7.   

    trunc和round
    trunc是取整
    round是四舍五入取整
      

  8.   

    兄弟们,有没有进位取整的函数
    即:XXXX(3.1223)=4
      

  9.   

    用format把你要的float,转化成你要的格式,然后再用strtoint!这样也可以!
      

  10.   

    if float_x>=0 then int_x:=trunc(float_x+0.0005) 
    else int_x:=trunc(float_x-0.0005)