四舍五入函数

引入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函数

posted on 2015-01-14 23:48  浮沉魅影  阅读(187)  评论(0编辑  收藏  举报

导航