要求有两个参数的那种,
想了好久没有头绪,
望高手指点……

解决方案 »

  1.   

    我看了http://www.delphibbs.com/keylife/iblog_show.asp?xid=10584这篇帖子,
    感觉delphi的round函数有很多问题,
    但是我是新手,对delphi了解不多,
    高手帮忙一下~
      

  2.   

    第一个参数就是要round的数,
    第二个参数是round的精度,可取负数,
    如:round(13.14,1)=13.1
        round(13.14,-1)=10
      

  3.   

    http://community.csdn.net/Expert/topic/4592/4592417.xml?temp=.7033808
    看看僵哥的DRound函数,声明改成
    function DRound(Value:double;cnt:integer):double;就好了。
      

  4.   

    汇编??
    我要疯了~根本看不懂,
    谁能给翻译成delphi啊?
      

  5.   

    如果Delphi好写,我就不使用汇编了.不过其实也只是一个近似值,精确度还是比较有限的.
      

  6.   

    下面是一个C版本的
    ------------------
    #include <math.h>
    //--------------------------------------
    //四舍五入
    //例:1.535
    //保留小数点后两位,做四舍五入得1.54
    //使用方法:Round(1.535,2)
    //返回值:1.54
    //--------------------------------------
    extern "C" __declspec(dllexport)
           double __stdcall Round(const double Value,
                                  const short int ADigit=0,
                                  const short int RoundMark=0
                                 )
    {
       char LocalRoundMark=RoundMark;
       double Result=Value;
       double DResult;
       if(ADigit>18)
          return Result;
       double DigitValue=powl(10,ADigit);   if(LocalRoundMark>0)LocalRoundMark=1;
       if(LocalRoundMark<0)LocalRoundMark=-1;   switch(LocalRoundMark)
       {
          case -1://Round Down
               Result*=DigitValue;
               if(Value<0.00)//负数
                  Result=ceill(Result);
               else
                  Result=floorl(Result);
               break;
          case  1://Round Up
               Result*=DigitValue;
               if(Value<0.00)//负数
                  Result=floorl(Result);
               else
                  Result=ceill(Result);
               break;
          default://Round  四舍五入
               if(Value<0.00)//负数
                  Result-=0.5/DigitValue;
               else
                  Result+=0.5/DigitValue;
               Result*=DigitValue;
               DResult=Result;
               if(Value<0.00)
               {
                  Result=ceill(Result);
                  DResult=Result-DResult;
                  if(DResult>0.9999999999)Result-=1.0;
               }
               else
               {
                  Result=floorl(Result);
                  DResult=DResult-Result;
                  if(DResult>0.9999999999)Result+=1.0;
               }
       }
       Result/=DigitValue;
       return Result;
    }
      

  7.   

    看出来僵哥是个高人了,
    但是我们的前台程序必须要用delphi写,
    郁闷~!