Survey123 - Leading Zeros for integer

2228
2
Jump to solution
04-23-2020 10:36 AM
PanGIS
by
Occasional Contributor III

Hi guys,

I need to format a field to 4 digits in this way:

the user would input a number and 

if 1 ----> the resulting number is 0001

if 12 ----> the resulting number is 0012

Is it possible to format this?

the field type is an integer and I put a length limit to 4.

thanks!

0 Kudos
1 Solution

Accepted Solutions
IsmaelChivite
Esri Notable Contributor

This would do the job, assuming that your integer question has nu for name.

if(string-length(${nu})=1,concat("000",${nu}),if(string-length(${nu})=2,concat("00",${nu}),if(string-length(${nu})=3,concat("0",${nu}),${nu})))

For example:

typenamelabelcalculationbind::esri:fieldType
integernuA numbernull
calculatenu_trailA number (trailing 0)if(string-length(${nu})=1,concat("000",${nu}),if(string-length(${nu})=2,concat("00",${nu}),if(string-length(${nu})=3,concat("0",${nu}),${nu})))esriFieldTypeString

View solution in original post

2 Replies
IsmaelChivite
Esri Notable Contributor

This would do the job, assuming that your integer question has nu for name.

if(string-length(${nu})=1,concat("000",${nu}),if(string-length(${nu})=2,concat("00",${nu}),if(string-length(${nu})=3,concat("0",${nu}),${nu})))

For example:

typenamelabelcalculationbind::esri:fieldType
integernuA numbernull
calculatenu_trailA number (trailing 0)if(string-length(${nu})=1,concat("000",${nu}),if(string-length(${nu})=2,concat("00",${nu}),if(string-length(${nu})=3,concat("0",${nu}),${nu})))esriFieldTypeString
PanGIS
by
Occasional Contributor III

Sorry for the late answer: it is exactly what I was looking for!

0 Kudos