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_
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值