Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Adding Zeros in Front of a Number to Reach Certain Number of Digits

atamertarslan
8 - Asteroid

Dear all,

 

I have a very basic question.

 

Imagine I have a list consisting of many entries with integer values of different number of digits, sometimes 5 sometimes 7. In the end I want to have a string with 10 digits/chars. That means if an entry has 5 digit number then 5 times zero should be added in front of that integer, if it has 7 digit number then 3 times zero.

 

Obviously, I can do this with a giant if else loop but I would very much appreciate an elegant way that will save me some time!

 

Best,

Atamert

3 REPLIES 3
PhilipMannering
16 - Nebula
16 - Nebula

You can use the Formula Tool,

 

 

padleft([Field1], 10, '0')

 

 

You would need to make sure [Field1] is a string by either using the Select Tool or ToString([Field1]).

kyle
5 - Atom

Any way we can use this for a double data type? Says for string only.

LATHROPS
7 - Meteor

Try in the formula tool:

 

tonumber(padleft(tostring([field1],#),10,"0"))

 

Might take a bit of experimentation, but this should work. In the example above, the # is the number of decimal places.  Not sure if a double data type will store leading zeroes though, so you might not want to convert back to a number.

Labels