Delphi中str函数用法

delphi中F1里讲的很明白了
Delphi syntax:
procedure Str(X [: Width [: Decimals ]]; var S);
Description
In Delphi code, Str converts X to a string representation according to the Width and Decimals formatting parameters. The effect is like a call to Write except the resulting string is stored in S instead of being written to a text file.
X is an integer-type or real-type expression. Width and Decimals are integer-type expressions. S is a string-type variable or a zero-based character array variable if extended syntax is enabled.
F1里的例子
function MakeItAString(I: Longint): string;
{ Convert any integer type to a string }
var
  S: string[11];
begin
  Str(I, S);
  Result:= S;
end;
begin
  Canvas.TextOut(10, 10, MakeItAString(-5322));
end;
懒的翻译了,直接给你摆了一个解释:
Str是将实数或整数类型的值转换为相应的字符串,比如Str(7,S),那么,S中就是 '7 ',而对于实数,可以通过Str来进行格式化,比如你的Str(S3,8,2)就是说将S3的小数部分保留2位,多余的部分四舍五入,总的数字个数为8不包扩小数点,多余的部分在生成的字符前补从空格,比如: 
Str(165.345:4:2,S),则S中为 '165.35 ' 
Str(165.345:5:1,S),则S中为 '   165.3 ',你可以看出小数部分只有一位,而前面补充了一个空格。
转自:http://zhidao.baidu.com/link?url=MxmBEPodOzDA1eXIRRyHzMWP1HztLT0guQcCUmKanstypInRjLqcStiG8U6tDcsh0VLJZw0o-K0kv8bf3Y47C_

你可能感兴趣的:(Delphi中str函数用法)