How to convert a text into a number?

Hi all,

I use pulldata () function and got the values a text format for number; e.g: in the .csv external file it comes as a text ‘500,000’ . I want to convert it to an integer 500,000. What is the function to convert this text into a number.

Many thanks

@lazasoa, you could use the int() function or the number() function to convert a string to an integer as outlined in the image shared below:

In the survey tab of your xlsform:

Data entry screen as seen in Enketo:

Reference xlsform:

String to integer.xlsx (10.6 KB)

1 Like

@Kal_Lam Thank you so much. It works!

1 Like

Hello @Kal_Lam. in the case of use a calculate the data result have a apostrophe, for example: '52 , there are a way to transforme in to a number?, for example only: 52.

Regards

Welcome back to the community, @Erosfaus! Have you tried checking and unchecking this option to see if should solve your issue:

Hello @Kal_Lam , not yet, but i will try.

Thanks.

hi @Kal_Lam , i have the same issue as @Erosfaus . I have tried using number() / int() with the pull data code as well as this suggestion of checking and unchecking the option, but it did not solve the issue. my data from calculation items is still read as text instead of numeric.

do you have a sample on how to properly apply the number() or int() with the pulldata function? i think this is where I am doing something wrong-- number(pulldata(a,b,c,d))?

Hello @hm11,
Where do you see it as “text”? If this is in your export only, it probably depends on your (advanced) download settimgs: Do not use legacy, and select text as numbers option)…

1 Like

hi @wroos, it is when exporting the raw data. here is my current download settings

@hm11, please be informed that data fields pulled from a .csv file are considered to be text strings, therefore, you use need to use the int() or number() functions to convert a pre-loaded field into numeric form. You could do this in a calculate variable.