在delphi6中,想保留小数点后2位数字,4舍5入的函数是什么?我用了RoundTo和SimpleRoundTo两个函数都有问题。
a:=27686.745
b:=38222.295
RoundTo(a):=27686.74,应为27686.75
SimpleRoundTo(b):=38222.29应为38222.30

解决方案 »

  1.   

    用format:
    a:=StrToFloat(format('%0.2f',[a]));
      

  2.   

    function Round(X: Extended): Int64;Description
    ...
    If X is exactly halfway between two whole numbers, the result is always the even number. This method of rounding is often called "Banker's Rounding".Note: The behavior of Round can be affected by the 
       ***Set8087CW*** 
    procedure or 
       ***SetRoundMode*** 
    function
      

  3.   

    a:=format('%.2f',[a])就可以了
    再给你提供一个输出格式方法:
    formatfloat(',#',1234556)输出就是1,234,556格式
      

  4.   

    round函数就可以了!或者搜索呀,很多这方面的资料的
      

  5.   

    round经常会截错的,最好是加一个0.00001后再round
      

  6.   

    StrToFloat(format('%0.2f',[a]));
      

  7.   

    我把a,b定义为double型,因为不存在float型。
    StrToFloat出错,请问该怎么改?
      

  8.   

    StrToFloat(format('%0.2f',[b])); 结果是38222.29
      

  9.   

    StrToFloat(format('%0.2f',[b]));结果为38222.29