引入math单元
function RoundEx(Value: Extended; RoundMode: TFPURoundingMode = rmUp): Int64;
var
RM: TFPURoundingMode;
begin
RM := GetRoundMode;
try
SetRoundMode(RoundMode);
Result := Round(Value);
finally
SetRoundMode(RM);
end;
end;
举例:
i := RoundEx(11.5) 结果: i=12
i := RoundEx(10.5) 结果: i=11
举例:
i := RoundEx(11.5, rmTruncate) 结果: i=11
i := RoundEx(10.5, rmTruncate) 结果: i=10
RoundEx函数华丽的变身为Trunc函数