谢谢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~) ,你给函数比我写的好多了^_^
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;