format()函数的简介
语法如下:
function ForMat(const ForMat:string;const Args:arry of const);
复制代码
注: format()是一个格式化函数;format参数是个一个格式参数,它主要用于格式Args里面的值,Args是一个变体数组,它可以有多个参数,而且每一个参数都可以不同。返回按指定方式格式化一个数组常量的字符形式。
格式指令:
"%" [index ":"] ["-"] [width] ["." prec] type
"%" [索引 ":"] ["-"] [宽度] ["." 摘要] 类型
复制代码
type类型有:d,u,f,e,g,n,m,p,s,x.
类型详解如下:
d代表十进制数;
u代表无符号整型;例:ForMat('this is %u',-2) ->this is 4294967294
f代表浮点数; 例:ForMat('%f',2.0) -> 2.00
e代表科学计数法 eg:Format("this is %e",-2.22)-> this is -2.220000E+000
g只能对应浮点型 eg:Format("this is %g",02.200) ->this is 2.2,去除多余的数
n只能对应浮点型 eg:Format("this is %n",4552.2176) -> this is 4,552.22 将值转化为号码的形式,保留两位小数
m表示钱币类型 eg:Format("this is %m",9552.21) -> this is ¥9,552.21 只对应浮点值
p表示指针类型 eg:Format("this is %p",p) -> this is 0012F548,返回指针地址,十六进制表示
s表示字符串类型 eg:Format('this is %X',string) -> this is "abxd"
x必须是一个整型 eg:Format('this is %X',15) -> this is F,十六进制返回
复制代码
以上为简单介绍Format函数
详细介绍可以参考:blog.csdn.net/loveliuzz/a…