How to add a leading zero to a text field in crystal reports

I am trying to come up with a way to add a leading zero to the value of a row field. For example, I have 12345, but I need a formula that converts it to 012345. I am new to Crystal, because I know that this is probably a simple formula, but it does not seem to work.

12345 => 012345  (add leading zero to make it 6 chars)

Thanks in advance.

+5
source share
7 answers

try it

totext (your_number, "000000");

1st argument: Well, this is the input.

2nd arg .: The number of digits you need in the output.

For ex,

num = 1234;

totext (num, "000000");

Conclusion:

001234

And if you want to add a fixed number of zeros, you can just use (add 3 leading zeros):

"000" + totext (your_number, 0);// 3

. , .

+5

:

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

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
+4

, (open explorer) → ( ) → --- > (xyz) → ** ToText ({DataTable1.Sr_No}, "0000" ) **

/ **,

,

Sr_No. 0001 0002 0003

+1

'0' + yourstringchar

0

,

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

  if length(yourstring) >= LENGTH 
        then yourstring 
  else
        yourstring + replicatestring('0',LENGTH-length(yourstring)) 

- kanthi

0
Right("00000000"&ToText({Table.correla}),8)
0

:

replace((space((20)-len({Table.Field}))+({Table.Field}))," ","0")

, . , , ((XX)...

, , . , , .

0

All Articles