cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Expression to keep leading zero in a number

mtran21
New Contributor III

I am using Mapper snap to map an integer column from database to CSV file. How do you write expression for this field โ€œMyNumโ€ to keep the leading zero in the csv file? like 04567

Thanks

3 REPLIES 3

marija_nikolovs
New Contributor II

Hi @mtran21

In mapper you just do next: โ€œ0โ€ + $MyNum and you have โ€œMyNumโ€ as string now.

Hope this is what you needed.

BR

igormicev
Contributor

Hi @mtran21

What is the desired length with leading zeroes? you could have examples like 00123, 01234, or 00001.
Under the assumption that you know the length, for example 5 here, then you could do something like:

("00000"+$MyNum.toString()).slice(-5)

and youโ€™ll always be having leading zeros and lengths == 5.

HTH

mtran21
New Contributor III

Thank you. This worked good