Converting String value into Numbers

I have instances where calculations are converted into numbers - Like every yes is coded in as 1 and no is coded in as 0. Similarly I have calculations like Total Students - Present Students = Absent Students. In all these cases I get the response as strings.

I understand adding number() is supposed to help in converting these numbers but in case of taking the entries right at the Yes No selection, is there way to code them to be picked as numbers itself?

Any one, Any thoughts, When I calculate, is there a way to convert the final results into numbers and not show up like text? Is the only way to add another calculation that converts them into numbers?

Being a Data Manager when I recieved Data into CSV format what i do, I create one do file in Stata which will recode and label my dataset that looks like label.txt (599 Bytes) STATA DO FILE.

This work I usually do when my team is working on ODK form and once I get the final form I test my Stata Do-file with the output of ODK form.

If you can attach your ODK form that will be more helpful.

Best,
@iamnarendrasingh

.

1 Like

Hello Narendra, Thank you ! :slight_smile: In my situation here though, I am trying deploy this for an in-classroom program and then leave the classroom with the access to everything. For this reason, I am looking to make as many possibilities in the input side itself, so there is minimum modification to the output file, and we have some basic takeways ready. I will share the file in a little bit. I am trying to make some changes and I hope they work. I will share them anyways.

The deal is, I think we can overlap 2 different calculation statements like say

number(round(${total_students} -${present_students},2))

I just seem to be doing something wrong somewhere.

Could you share your ODK form so I can check more.

Best,
@iamnarendrasingh

1 Like

Have you tried converting your input to round() as well, or are you sure they are already numbers?
round(number(${total_students}) -number(${present_students}),2)
Also, if you are using Excel, make sure your cells are of type "general"

best
/emil

2 Likes

Thank you Emil, so the Total Students and Present Students are Integer entries in the input (so I assume they are numbers, no?) Also, this multiversing of calculations is something I get confused with. What you have done here is a great example of how it is to be done. When i do it, I end up doing it as number(round(${.... and somewhere it seems to get incorrect.

Yes, data types can be tricky.
In your case I suppose the numbers are integers, so there should be no need for round(). You can always use number() to make sure you actually have a number type.

You say you get the response as a string - how do you experience that? Is that when you are doing further calculation on it?

1 Like

Yes, so when I have entries for Total Students, it comes in integers, Present Students is also integers. The calculation for Absent Students, and % of Attendance then are calculated. But these show up as NaNs

Check the document https://docs.opendatakit.org/form-logic/#empty-values-in-math

1 Like

Maybe I used the terms incorrectly, but these calculations give me results, but in the output files, they come as "general" and not "number formats.

Sorry if I misunderstand, when you say "output files" are you talking about the exported xlsx files? In that case, "general" as cell type should be just fine?
@ARIF_AZAD_KHAN is correct in pointing you towards the coalesce function to get rid of NaN (not a number), since that could be caused by empty (string) values