返回整数的四种情况

    技术2022-05-20  36

     

    //返回整数的四种情况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 的一倍以上}


    最新回复(0)