03-03-2023 07:30 AM
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
Solved! Go to Solution.
03-03-2023 07:54 AM
It is because the COUNT is an integer, try with this:
"0000000000".slice($COUNT.toString().length) + $COUNT
03-03-2023 08:43 AM
That worked perfectly! You rock!
03-03-2023 07:40 AM
@heidi.andrew - one other option - a while back, I created a set of library expression files, one of which contains LPAD and RPAD functions. Basically, this simplifies this type of expression and prevents multiple solutions to the problem from different developers.
I hope this helps!
03-03-2023 08:19 AM
i have been in that one a lot but nothing works for me. I tried several iterations of this:
lib.string.lpad(‘123’, 5, ‘0’) yields “00123”
i brought it into a mapper field. Is that the right snap? I changed the " from the curved version and still get the error like this:
03-03-2023 08:33 AM
Can you share your pipeline? If you have the library referenced in your pipeline then the statement you show should work.
03-03-2023 08:37 AM
If you have a guaranteed numeric value (integer) you can simply use "%010d".sprintf($COUNT)
to get a string out, you can do similar with float values, but you have to be a bit more tricky about it. I believe it follows the Java util formatter specification.