返回整数的四种情况

//返回整数的四种情况

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 的一倍以上}

*本文来自万一的博客

原文地址:https://www.cnblogs.com/CNQCJ/p/1402433.html