返回整数的四种情况

//返回整数的四种情况
const
  a = 1.8;
  b = -1.8;
begin
  {返回比值大的最小整数:}
  ShowMessage(IntToStr(Ceil(1.8)) + ',' + IntToStr(Ceil(-1.8)));    {返回:2,-1}

  {返回比值小的最大整数:}   ShowMessage(IntToStr(Floor(1.8)) + ',' + IntToStr(Floor(-1.8)));  {返回:1,-2}

  {删除小数部分:}
  ShowMessage(IntToStr(Trunc(1.8)) + ',' + IntToStr(Trunc(-1.8)));  {返回:1,-1}

  {四舍五入:}
  ShowMessage(IntToStr(Round(1.8)) + ',' + IntToStr(Round(-1.8)));  {返回:2,-2}
end;

{经我反复测试, 按性能排个序: Round、Trunc、Floor、Ceil; 应该多用 Round, 它的速度是 Trunc 的一倍以上}

posted @ 2011-03-02 10:07  吴越  阅读(215)  评论(0编辑  收藏  举报