dd1=6.55
dd2=14264.3
  dd:=dd1 * dd2;
  dd:=strtofloat(formatfloat('0.##',dd));
得到93431.16(实际是93431.165,但最后一位5没有四舍五入进1,为什么)然而
dd1=6.55
dd2=14264.3001
  dd:=dd1 * dd2;
  dd:=strtofloat(formatfloat('0.##',dd));
得到93431.17(实际是93431.166,最后一位6进1,为什么)如何在末位是5时进一位

解决方案 »

  1.   

    uses Math;function RoundingOff(const Value: Extended; const Digit: integer): Extended;
    var
      vLFactor: Extended;
    begin
      vLFactor := IntPower(10, Digit + 1);
      Result := Trunc((Value * vLFactor + 5) / 10) / IntPower(10, Digit);
    end;
      

  2.   

    dd1=6.55
    dd2=14264.3
    dd:=dd1 * dd2;
    dd:=trunk(dd*100+0.5)/100
      

  3.   

    不好意思,打错了字母了:
    dd1=6.55
    dd2=14264.3
    dd:=dd1 * dd2;
    dd:=trunc(dd*100+0.5)/100
      

  4.   


    直接调用就好了,有什么复杂的?
    返回值 := RoundingOff(数字,保留的小数位)
      

  5.   

    math.SimpleRoundTo(0.125,-2)试一下
      

  6.   

     RoundTo函数,搭配 SetRoundMode使用,SetRoundMode设置舍入方式
    roundto执行舍入操作。
      

  7.   

    只保留两位: value为传入的值  if value>=0 then
         result:=int(value*100+0.5)/100
      else
         result:=int(value*100-0.5)/100
      

  8.   


       str(strtoreal(dd):x:y,dd);  x=字段最大长度,y=取多少小数位
        dd:=trim(dd);   
      

  9.   


    我的delphi2010里roundto是五舍六入,SimpleRoundTo是四舍五入没错呀。
      

  10.   

    唉,还是把俺多年的存货贡献出来吧。久经考验呀
    function comm_Round(dFigure:double;iDecimals : integer): double; //四舍五入函数;
    var
      iIER : integer;  //乘数
      i : cardinal;
      dTmp : double;
    begin
      iIER := 1;
      for i:=1 to iDecimals do
          iIER := iIER*10;  dTmp := dFigure * iIER;
      if dFigure>0 then //正数
      begin
         if frac(dTmp)<0.5 then
            dTmp := Trunc(dTmp)
         else
            dTmp := Trunc(dTmp) + 1;
         result :=  dTmp/iIER;
      end
      else  //非正数
      begin
         if frac(dTmp)>-0.5 then
            dTmp := Trunc(dTmp)
         else
            dTmp := Trunc(dTmp) - 1;
         result :=  dTmp/iIER;
      end;
    end;
      

  11.   


    四舍六入。变通一下就就行啦!!!!!!!!!
    math.roundto(0.12345 + 0.001, -2)
      

  12.   


    我是这么做的,可以啊
    var
    ab:real;
    begin
    ab :=strtofloat(edit1.Text);
    edit1.Text :=FormatFloat('#.##',ab);
    end;
      

  13.   

    round()  四舍五入;
    trunc() 不四舍五入;
    ceil()  有余数就进1.不过要在uses中加入math.你自己试试吧。
      

  14.   

    procedure TForm1.Edit1Exit(Sender: TObject);  //四舍五入2位
    var
    ab:real;
    dd,cc,ee:real;
    begin
    ab :=strtofloat(edit1.Text);
    edit2.Text :=floattostr(RoundingOff(ab,2));
    dd:=((ab*1000+5)/10);
    cc :=Trunc(dd);     
    ee :=cc/100;
    edit4.text :=floattostr(ee);
    end;
    end.我也遇到这个问题,所以刚做了一个,可以的久经考验
      

  15.   

    原数扩大100倍后加上0.5,然后用round取结果,将结果再除以100。
    绝对没有问题的算法,超简单的东西。