前导0的格式化数值字符输出

字体大小: 中小 标准 ->行高大小: 标准
在Delphi中没有前导0输出的函数,如C语言中printf("%08d",10);就会输"000000010",但是在实际应用中经常会用到此种函数,如财务等数据的输出。如何实现?以下的代码实现了这种功能, 

function qd0str(const count,num:integer):String; 
Var 
 s1,s2:String; 
begin 
 s1:=IntToStr(Num); 
 s2:='00000000000000000000'; 
 if (Length(s1)>=count) then 
  s2:='' 
 else if(count>20) then 
  SetLength(S2,20-Length(s1)) 
 else 
  SetLength(S2,count-Length(s1)); 

 Result:=S2+S1; 
end; 
  
函数的参数count为输出字符串的总长度,在函数中定义为最大20。Num为需要转换成字符串的数据。

此文章由 http://www.ositren.com 收集整理 ,地址为: http://www.ositren.com/htmls/67934.html