四舍五入函数

来源:互联网 发布:sql区分二范式和三范式 编辑:程序博客网 时间:2024/04/23 18:56

function DoRound(Value: Extended): Int64; 
  procedure Set8087CW(NewCW: Word); 
    asm    MOV     Default8087CW,
    AX    FNCLEX    FLDCW   Default8087CW  end;
const  RoundUpCW         = $1B32;var  OldCW             : Word;
begin  OldCW := Default8087CW; 
try   
  Set8087CW(RoundUpCW);   
  Result := Round(Value); 
  finally  
    Set8087CW(OldCW);
  end;
end;
---------------------------
---------------------------


function RoundFloat(f:double;i:integer):double;
var
  s:string;
  ef:extended;
begin
  s:='#.'+StringOfChar('0',i);
  ef:=StrToFloat(FloatToStr(f));//防止浮点运算的误差
  result:=StrToFloat(FormatFloat(s,ef));
end;

原创粉丝点击