问题如上,

解决方案 »

  1.   

    function ReturnMore(input : Currency; Leng : Integer) : String;
    var
      w,iLoop,iLeng : Integer;
      cDec : Currency;
      s,str,sDec : String;
    begin
      w := pos('.',FloatToStr(input));
      if Leng = 0 then
      begin
        Result := copy(FloatToStr(input),1,w-1);
      end
      else
      begin
        if w = 0 then
        begin
          sDec := '';
          for iLoop := 0 to Leng-1 do
          begin
            sDec := sDec+'0';
          end;
          result := FloatToStr(input)+'.'+sDec;
        end
        else
        begin
          s := copy(FloatToStr(input),1,w+Leng);
          iLeng := Length(trim(copy(s,w+1,Leng)));
          if copy(s,w+Leng,1) = '' then
          begin
            sDec := '';
            for iLoop := 0 to Leng-iLeng-1 do
            begin
              sDec := sDec+'0';
            end;
            result := FloatToStr(input)+sDec;
          end
          else
          begin
            str := copy(FloatToStr(input),w+Leng+1,1);
            if str <> '' then
            begin
              if StrToFloat(str) >=5 then
              begin
                cDec := 1;
                for iLoop := 0 to Leng-1 do
                begin
                  cDec := cDec/10;
                end;
                result := FloatToStr(StrToFloat(s)+cDec);
              end
              else
                result := s;
            end
            else
              Result := FloatToStr(input);
          end;
        end;
      end;
    end;
      

  2.   

    Frac可以只取小数部分,int取整数部分,FormatFloat或者format或者str均可得到各式样的小数位