Expression to keep leading zero in a number
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2021 09:18 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2021 05:40 AM
Hi @mtran21
In mapper you just do next: “0” + $MyNum and you have “MyNum” as string now.
Hope this is what you needed.
BR

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2021 08:55 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2021 11:54 AM
Thank you. This worked good
