四舍五入
//四舍五入加强版,可指定到小数后几位
function RoundPlus(Value: Extended;Length: Integer): Extended;
procedure Set8087CW(NewCW: Word);
asm
MOV Default8087CW,AX
FNCLEX
FLDCW Default8087CW
end;
const
RoundUpCW = $1B32;
var
OldCW : Word;
s: string;
begin
if Length = 0 then
s := '0'
else
s := '0.' + Repl('0', Length);
OldCW := Default8087CW;
try
Set8087CW(RoundUpCW);
Result := StrToFloat(FormatFloat(s, VarToFloat(Value)));
finally
Set8087CW(OldCW);
end;
end;
function RoundEx (const Value: Real): integer;
var
x: Real;
begin
x := Value - Trunc(Value);
if x >= 0.5 then
Result := Trunc(Value) + 1
else Result := Trunc(Value);
end;
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/archive/2007/10/14/2940912.html