四舍五入的BUG

字体大小: 中小 标准 ->行高大小: 标准
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://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/67924.html