cancel
Showing results for 
Search instead for 
Did you mean: 

Pad field with zero

heidi_andrew
Contributor

How can i take a sql result field where I am counting the number of people in the file for a trailer and left pad with zeroes? I have tried a bunch of the expressions shown in several of the answers here but nothing is working. I get
image

1 ACCEPTED SOLUTION

It is because the COUNT is an integer, try with this:

"0000000000".slice($COUNT.toString().length) + $COUNT

View solution in original post

10 REPLIES 10

jcornelius
New Contributor III

This is the one I always use
Where 9 is the size you want and text2 is you data (-9 negative of size you want)
‘0’.repeat(9).concat(text2).slice(-9)

Explain:

text1 = “000000000”; //length you want

text2 = “1234”;

result = “000000000”.concat(text2);

0000000001234
//returns last number of characters
let result2 = result.slice(-9); //length you want

000001234

‘0’.repeat(9).concat(text2).slice(-9)