โ02-04-2020 09:56 AM
I have strings that are storing a two digit number (i.e. 00, 01, 02, etc) but I need to add another leading zero (i.e. 000, 001, 002). I donโt want to simply concatenate a 0 on the front in case I have values that end up being three digits.
Solved! Go to Solution.
โ02-04-2020 02:11 PM
Thank you @tstack! That worked!
โ02-04-2020 10:56 AM
Should be doable with sprintf() string function.
โ04-30-2020 07:30 AM
This worked well. I was padding a string with spaces. Beware that when I validated the pipeline the string in the preview data was not displayed with the padding, but the string was actually padded as expected.
โ02-04-2020 12:20 PM
$value = โ01โ.
Iโve tried $value.sprintf(โ%03dโ, โ0โ) and several other similar things but it doesnโt seem to work.
โ02-04-2020 01:19 PM
It looks like the format and the value to format are switched around. The sprintf()
method is to be called on the format string, like so:
"%03d".sprintf(parseInt($value))
Note that the value passed in needs to be a number and not a string, which is why I used parseInt()
.