如何将前导零添加到水晶报表中的文本字段

Dag*_*200 5 formula crystal-reports leading-zero crystal-reports-formulas

我试图想办法将一个前导零添加到字符串字段值.例如,我有12345,但需要一个公式,将其转换为012345.我是Crystal的新手,因为我知道这可能是一个简单的公式,但似乎无法让它工作.

12345 => 012345  (add leading zero to make it 6 chars)
Run Code Online (Sandbox Code Playgroud)

提前致谢.

Rya*_*yan 5

用零填充数字字符串值到特定长度:

local numbervar yournum := tonumber({table.your_string}); //convert to number
totext(yournumnum, '000000') //convert back to padded string of length 6
Run Code Online (Sandbox Code Playgroud)

OR 用于通用字符串

local stringvar yourstring:= {table.your_string};
local numbervar LENGTH := 10; //The desired padded string length

if length(yourstring) >= LENGTH then yourstring else
  replicatestring('0',LENGTH-length(yourstring)) + yourstring
Run Code Online (Sandbox Code Playgroud)


Bha*_*kar 5

试试这个

totext(your_number,"000000");

1st arg.:嗯,这是输入.

2nd arg.:输出中需要的位数.

对于前者,

num = 1234;

totext(num,"000000");

输出:

001234

而且,如果你想添加固定数量的零,那么你可以使用(添加3个前导零):

"000"+ totext(your_number,0); //添加3个前导零

注意:最终输出是字符串而不是数字.


Gue*_*rra 0

只需将您的字段“0”+yourstringchar