两位数简单,直接IntToStr就行了,
但是个位数呢?用什么函数呢?

解决方案 »

  1.   

    我现在暂时用的自己写的一个函数:
    function MyFunc(N: Integer): string;
    begin
      Result := IntToStr(N);
      if Length(Result) = 1 then
        Result := '0' + Result;
    end;
      

  2.   

    function IntToStr(value, size:integer):string;overload;
    var
      i : integer;
    begin
      result := IntToStr(value);
      for i := 1 to size - Length(result) do
      begin
        result := '0' + result;
      end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
      Edit1.Text := IntToStr(4, 2);
    end;
      

  3.   

    procedure TForm1.Button2Click(Sender: TObject);
    var
      i:integer;
    begin
      i:=4;
      caption:=FormatFloat('00',i)
    end;
      

  4.   

    S := Format('%.2d', I);
      

  5.   

    谢谢postren(小虫),谢谢你的提醒,我真是太粗心了,Delphi帮助中关于Format strings有这样一段描述:
      d Decimal. The argument must be an integer value. The value is converted to a string of decimal digits. If the format string contains a precision specifier, it indicates that the resulting string must contain at least the specified number of digits; if the value has less digits, the resulting string is left-padded with zeros.
      里面就讲到了为整数指定精度其实就是指定了返回字符串的宽度,宽度不足就会在左边补零。
    也谢谢 hch_45(HCH ~ahong.net~) ,你给函数比我写的好多了^_^