请问,如何将一个float型的数值(如100.36)四舍五入?
谢谢!

解决方案 »

  1.   

    http://expert.csdn.net/Expert/topic/1179/1179244.xml?temp=.6055261
      

  2.   

    var a:real;
    a:=100.36
    round(strtofloat(a));
    就ok了
      

  3.   

    用Roundto函数,具体用法看帮助,很详细
      

  4.   

    delphi6可以用ROUNDTODELPHI5:用function MyRound(X: Extended; APrec :integer) :Extended ;
    var
      BaseNum :Extended ;
    begin
      BaseNum := Power(10, APrec) ;
      Result := Round(X * BaseNum + 5 / BaseNum) / BaseNum ;
    end;
      

  5.   

    //==============================================================================
    //标准四舍五入进位**************************************************************
    //==============================================================================
    function StanRoundTo(const AValue: Double; const ADigit: TRoundToRange = -2): Double;
    var LFactor: Double;
    begin
      LFactor := IntPower(10, ADigit);
      Result := (Trunc(AValue / LFactor) + IfThen(Frac(AValue / LFactor)>=0.4999, 1, 0)) * LFactor;
    end;
    //==============================================================================
    //强制向上进位******************************************************************
    //==============================================================================
    function OverRoundTo(const AValue: Double; const ADigit: TRoundToRange = -2): Double;
    var LFactor: Double;
    begin
      LFactor := IntPower(10, ADigit);
      Result := (Trunc(AValue / LFactor) + IfThen(Frac(AValue / LFactor)>=0.0999, 1, 0)) * LFactor;
    end;//==============================================================================
    //强制向下进位******************************************************************
    //==============================================================================
    function DownRoundTo(const AValue: Double; const ADigit: TRoundToRange = -2): Double;
    var LFactor: Double;
    begin
      LFactor := IntPower(10, ADigit);
      Result := (Trunc(AValue / LFactor) + IfThen(Frac(AValue / LFactor)>=0.9999, 1, 0)) * LFactor;
    end;
      

  6.   

    用FormatFloat最简单了,如333.1456取小数后两位数:    FormatFloat('0.00',333.1456);  //返回的是string;具体请看Delphi Help,内有详细例子。