# Include zero value before number

Hello,

For our work, we collect several data points that needs to be a string of digits called the Screening Number, 9 numbers long. One of the questionnaires that we deploy yields a score of 0-27.

See Image Below.

However, when that questionnaire yields a total from 0-9, I would like to have a 0 precede it. For example, the total would be 9, but Kobo would show that value as 09. The image below is only 8 digits long, but needs to be 9 for the Screening Number. How do I ensure that a zero value precedes the number 9?

See Image Below.

Thank you.

Hi @Kal_Lam - I’m still not able to complete this. I sent you a personal message. Would you mind taking a look there? Thank you.

For more information, if the number is 0-9, I need it to show up as 00 or 03, etc. with a zero at the beginning in a longer string of digits, 9-long. It would come at the end 003054203.

I’ve tried this equation to no luck.
(regex(., ‘^[00-09]{2}\$’) and (. >= 00))

Is it that you only wish to enter from 0-9? So what is your expected input digits? The smallest and the largest?

The questionnaire will yield a digit anywhere from 0 to 27. There are 9 questions that a person has to respond to. Each question has a corresponding value from 0 to 3, hence the total being 0 to 27.

Then, the string of 9 digits takes other data into account such as counselor number, patient id, and visit number. The last two digits are earmarked for the value from the questionnaire. If the score is > 9, then it occupies both digits (ex. 10, 11, 15, 24, etc.). If the score is < 9, then it only occupies one digit (for now; ex. is 4, 5, 9). I’d like it occupy two digits and be consistent with scores > 9 (ex. 4 becomes 04, 8 becomes 08).

Hi @finemindorg, you can try something like this with the `concat()` method:

### survey

type name label calculation default
integer num Enter a number 0
calculate calc if(\${num} <= 9, concat(‘0’, \${num}), \${num})
note result The output is: \${calc}
1 Like

I’m not entirely sure where I input that.

Here is the form for reference.

https://ee.humanitarianresponse.info/x/c2NSQHjc

Hi Josh - I tried playing around with your suggestion, but didn’t get anywhere. Apologies if I’m not picking it up. Can I share my server information for you help on the backend?

Hi @finemindorg
It is first important to understand how numbers are integrated. Anytime a number is preceded by a zero, it becomes the number without the zero e.g. 01 becomes 1.

As such what you need in this case is not a number but a text question that codes your words as you need. The solution is what has been proposed by @Josh. However, you should know that you will need a calculation to run this, Are you familiar with using calculations?

The alternative to depicting this should be:

1. Create your number question as it is.
2. Create a text question and make it read-only and then add this formula in the calculation column if(\${num} <= 9, concat(‘0’, \${num}), \${num})

I recommend going through the article on calculations.

Stephane

2 Likes

@stephanealoo, thank you for the reframe. I figured it out! What a relief. I appreciate your guidance and for @Josh and @Kal_Lam for your speedy replies and persistence. I needed the entire team to push me along. I’m not great at this, but I appreciate your patience and willingness to lend a hand.

I’m excited to show it off to our team!

3 Likes