If X is exactly halfway between two whole numbers, the result is always the even number.
如果X剛好在兩數的中間,那回傳的數將會是 "偶數" 的那一個。
This method of rounding is often called "Banker's Rounding".
我才不管什麼 "Banker's Rounding" ,實用最重要。
在網路上找到很多資訊,加以小改一下成為台灣適用的『四捨五入』
就呼叫自己的 RoundF 吧!
function RoundF(X: Extended; Decimal: integer = 0): Extended;
var
PowerNum: Extended;
begin
PowerNum := IntPower(10, Decimal);
Result := RoundI(X * PowerNum) / PowerNum;
end;
function RoundI(X: Extended): Int64;
begin
if X < 0 then
Result := Round(X - 0.0000001)
else
Result := Round(X + 0.0000001);
end;
複製代碼
作者: bestlong 時間: 2011-3-8 11:49
參考樓上的修改成這樣
function RoundF(X: Extended; Decimal: integer = 2): Extended;