Delphi的四舍五入函数Round有BUG,无法正常工作。
对于XXX.5的情况,整数部分是奇数,那么会Round Up,偶数会Round Down,例如:
x:= Round(17.5) = x = 18
x:= Round(12.5) = x = 12
请使用下面的函数代替Round:
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;
本文地址:http://com.8s8s.com/it/it4597.htm