Number formatting: How to retain leading zeros, and display to two decimal places?

265 views
Skip to first unread message

Robert Fitzgerald

unread,
Oct 23, 2017, 5:36:16 AM10/23/17
to Kobo Users
Hello

I am having some difficulties with number fields. One field we use to collect telephone numbers, which here in the UK all start with a leading zero however Kobo seems to strip this out and will save the value without the zero at the beginning. Is there a way to change this behaviour?

I also run a calculation based on my input data which is a currency, this calculation needs to display the results to two decimal places. I've tried various tricks but I cannot seem to find one that works, is this possible?

Thanks in advance

ma...@de-france.net

unread,
Oct 23, 2017, 6:11:16 PM10/23/17
to Kobo Users
Hi Robert,
For your first query you will need to use a text field, to which you can add a regex constraint to make sure that only numbers are captured. For example it could be regex(.,'^([0-9]){14}$'). You can also set it up in such a way that it has to start with the UK indicator or else it isn't accepted.
Another solution if you don't like the fact that the number keypad doesn't appear with a text type question would be to add the 0 in an extra calculation (not very clean but functional!)

For your second query, you can use the round() function in your calculation:  round((${VALUE}),2).
Best,
Maeve

Peter Smith

unread,
Oct 23, 2017, 7:33:38 PM10/23/17
to Kobo Users
Hi Robert,

Another solution to your first question would be to make the phone number a "text" question, and then (in Kobo) set the Appearance as "numbers."

In XLSForm, you would write "numbers" in the Appearance column.

Robert Fitzgerald

unread,
Jan 8, 2018, 8:26:35 AM1/8/18
to KoBoToolbox Users
Thank you for this idea, this works well for us

Robert Fitzgerald

unread,
Jan 8, 2018, 8:29:57 AM1/8/18
to KoBoToolbox Users
Hi Maeve

Thanks for the suggestions, for the phone numbers I've gone down the option of a text input which works fine for us.

With the rounding to two digits, I am struggling to get it to work. I have added the round code into the formula but it seems to be ignored and shows the same whether with or without. 
The calculation I am using is: 
round((${softcalc})*2.50,2)
Which for my test example gives an output of 25 instead of 25.00 as I would like it to show.

Can you advise why this may be? 

ma...@de-france.net

unread,
Jan 8, 2018, 8:52:30 AM1/8/18
to KoBoToolbox Users
Hi Robert,
At first glance, your parenthesis are probably wrong depending what type of calculation you are trying to do (the example I had given earlier in the thread might not have been very clear!)-in your case I would probably use: round((${softcalc}*2.50),2)
Hope that helps.
Best,
Maeve
Reply all
Reply to author
Forward
0 new messages