⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dtqd0.html

📁 对于学习很有帮助
💻 HTML
字号:
<html>
<head>
   <meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
   <meta NAME="Author" CONTENT="FuGui">
   <meta NAME="GENERATOR" CONTENT="Mozilla/4.04 [en] (Win95; I) [Netscape]">
   <title>Delphi中前导0格式化输出</title>
</head>
<body TEXT="#663366" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#FF0000" BACKGROUND="Bk463.jpg" tppabs="http://www.nease.net/~borland/delphi/tips/Bk463.jpg">

<h1>
Delphi中前导0的格式化输出:</h1>
&nbsp;

<p>&nbsp;&nbsp;&nbsp; 在Delphi中没有前导0输出的函数,如C语言中printf(&quot;%08d&quot;,10);就会输&quot;000000010&quot;,但是在实际应用中经常会用到此种函数,如财务等数据的输出。如何实现?以下的代码实现了这种功能,

<p><b>function</b> qd0str(const count,num:integer):<b>String</b>;
<br><b>Var</b>
<br>&nbsp;s1,s2:<b>String</b>;
<br><b>begin</b>
<br>&nbsp;s1:=IntToStr(Num);
<br>&nbsp;s2:='00000000000000000000';
<br>&nbsp;<b>if</b> (Length(s1)&gt;=count) <b>then</b>
<br>&nbsp; s2:=''
<br>&nbsp;<b>else if</b>(count&gt;20) <b>then</b>
<br>&nbsp; SetLength(S2,20-Length(s1))
<br>&nbsp;<b>else</b>
<br>&nbsp; SetLength(S2,count-Length(s1));

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

<p>以上为本人个人观点,不对之处欢迎大家不吝赐教,谢谢。

此文放在此后,收到了许多朋友的来信,告诉我在Delphi中Format已经实现了这个功能,我仔细查看了Delphi的帮助后发现我真的是
有点... Delphi中对%[width] [&quot;.&quot; prec]d的说明为: 
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.
故使用Format就可以了. 
<br>
谢谢所有朋友,特别是告诉我的朋友.  我实际上从来没有使用这种需求,只是
有朋友问这个问题,我就评印象好象DelphiChat上有人问过这个问题,当时有朋友这个说过.
<br>
再次向所有朋友致谢,也向受我误导的朋友道歉.

<p>傅贵 于 98.3.25

<p>本页版主:<a HREF="mailto:fgui@usa.net">傅贵</a>,最后修改日期:98.2.19
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -