Is there a way to increment a variable with a calculation and maintain the original padding? I have a variable that's either going to be 001 or 01, and when I increment it, I'd like it to maintain that formatting. So far, all I've been able to do is set everything to a fixed padding with the Format option in the calculation action.
I can use Filter to get the character count, but I don't think I can use that with the calculation format, unless I'm missing something.
I can probably split out all the zeros and append them back to the variable after the calculation, but I figured there was probably a simpler way to do this that I'm missing.
Because of how KM handles variables and text (a good thing overall, in my mind), I don't think you can really maintain the leading zeros as you go. I always just do my calculations, then use a second variable to display the formatted results to whatever level I need to show them.
There's probably an easier/better way, though; I'm just not aware of it :).
Your solution suggestion, if modified a bit, would do the job perfectly, but I'm fairly confident someone will come up with a simple solution.
I'm working on a delightful, novel solution, but it may take longer than usual because I'm watching the US election results and making breakfast at the same time.
I have a solution. I enjoyed the challenge. I made it into a subroutine macro. Basically, what I did was add up the digits "manually in my macro." If there were leading zeros, I kept the zeros. I'm sure there are other solutions, which I'm still pondering, because I like this puzzle.
So convert the number to a format by replacing every digit with 0, Then create a CalculateFormat token with the format inserted (note the doubled percentage characters all through that text which are converted to single percent characters), and then process the tokens a final time to calculate the result and format it.
Thanks, Peter, this works great! Adding token support to the format field will be a nice addition, but it's cool to see all the alternate solutions, I learned some new stuff here.