Calculate a percentage from 2 entered values

I'm working on a survey using the build tool, and I'm would like to
calculate a percentage based on previous responses

Specifically
Q1. Average live weight
Q2. Average carcass weight
Q3. Dressed percentage

For question 3, I want to display the calculation of CarcassWt/LiveWt as a
percentage, and use the acknowledge button to accept (or swipe back and
edit earlier responses)

in the binding section for Q3, I'm using

           type="decimal" calculate="(/data/CarcasWt) div 

(/data/LiveWt) * (100)"/>

But I'm getting results like 0.87736256333862

I know it needs some sort of constraint language, but what will give me a
percentage with only 2 decimal places? I don't even care rounded up or
down.....

Thanks all.!
Ruth

There is a round(field, power-of-ten) function. For integer percentages,
you would use:

type="decimal" calculate="round( (/data/CarcasWt) div (/data/LiveWt) * (100) , 0)"/>

https://opendatakit.org/help/form-design/binding/ (similar to Excel).

Unfortunately, while the round() is handled with precision in the numeric
value, for some of these values, when they are displayed as a string, they
end up having a chain of zeros followed by non-zero values (e.g.,
1.330000021).

This is because some values are not representable in a binary number system
(e.g., 1/3), and because there is an inconsistency somewhere in the forms
processor when it converts these values into strings for display.

ยทยทยท On Wed, Apr 27, 2016 at 12:22 PM, Ruth Little wrote:

I'm working on a survey using the build tool, and I'm would like to
calculate a percentage based on previous responses

Specifically
Q1. Average live weight
Q2. Average carcass weight
Q3. Dressed percentage

For question 3, I want to display the calculation of CarcassWt/LiveWt as a
percentage, and use the acknowledge button to accept (or swipe back and
edit earlier responses)

in the binding section for Q3, I'm using

           type="decimal" calculate="(/data/CarcasWt) div

(/data/LiveWt) * (100)"/>

But I'm getting results like 0.87736256333862

I know it needs some sort of constraint language, but what will give me a
percentage with only 2 decimal places? I don't even care rounded up or
down.....

Thanks all.!
Ruth

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Hi? I worked around percentage formatting by performing the calculation e.g
${Q1} div ${Q2} * 100, Then i referenced the calculation like this,
${percentage_calculation}%.
It serves the purpose now.

ยทยทยท On 27 Apr 2016 22:22, "Ruth Little" wrote:

I'm working on a survey using the build tool, and I'm would like to
calculate a percentage based on previous responses

Specifically
Q1. Average live weight
Q2. Average carcass weight
Q3. Dressed percentage

For question 3, I want to display the calculation of CarcassWt/LiveWt as a
percentage, and use the acknowledge button to accept (or swipe back and
edit earlier responses)

in the binding section for Q3, I'm using

           type="decimal" calculate="(/data/CarcasWt) div

(/data/LiveWt) * (100)"/>

But I'm getting results like 0.87736256333862

I know it needs some sort of constraint language, but what will give me a
percentage with only 2 decimal places? I don't even care rounded up or
down.....

Thanks all.!
Ruth

--

Post: opendatakit@googlegroups.com
Unsubscribe: opendatakit+unsubscribe@googlegroups.com
Options: http://groups.google.com/group/opendatakit?hl=en


You received this message because you are subscribed to the Google Groups
"ODK Community" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to opendatakit+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

1 Like

Hi
Would you give me an example for this percentage calculation in an excel sheet.

Hi @Mosab_English

Here you go: percentages.xlsx (5.4 KB)

This should be the correct answer, and I'm a bit unclear why you added the caveat. round(1 div 3 * 100,0) will give you "33" [no decimal places], round(1 div 3 * 100,1) will give you "33.3" [1 decimal place], etc. Could you give an example where this will produce an unexpected result?

2 Likes

Thanks so much, your steps helped me