四舍五入的函数是什么???

解决方案 »

  1.   

    round函数。
    Returns the value of X rounded to the nearest whole number.
    function Round(X: Extended): Int64;DescriptionThe 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.If the rounded value of X is not within the Int64 range, a run-time error is generated, which can be handled using the EInvalidOp exception.
      

  2.   

    round,在DELPHI 的帮助中就有的,可以查到。
      

  3.   

    var
      n1,n2 : Integer;
    begin
      n1 := Trunc(FloatNum);
      n2 := Round(FloatNum * 10 - n1 *10)
      if n2 > 4 then
         n1 := n1 + 1;  
    end;
      

  4.   

    在DELPHI6中有ROUNDTO()否则,可以用function MyRound(X: Extended; APrec :integer) :Extended ;
    var
      BaseNum :Extended ;
    begin
      BaseNum := Power(10, APrec) ;
      Result := Round(X * BaseNum + 5 / BaseNum) / BaseNum ;
    end;
      

  5.   

    round函数就可以了,delphi5中的例子如下:
    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);
    end;