I am storing a value (number 1-5) in a drop down field and would like to do a calculation based on the numbers filled in. The only way I could get my calculation to work was to store the number (1-5) in a number field (not a drop down field) so I'm wondering if it's because the drop down content is seen as a string and not an integer. If so, perhaps I need to convert the string to an integer. Although I have it working with the value (1-5) stored in a number field, I'd like to understand how I could make it work with a drop down. I saw another post that sounded similar: How can I convert a dropdown field value to an integer within a hash?
Here is my template code that works with my number field:
<!-- AORTA -->
<!-- Get entries for study type Aorta for logged in sonographer. Filter out any scores that are default zero. -->
{% set imageQualityScoreAorta = craft.entries.section('logsQA').logGeneral_statusWorkflow('reviewed').search('logGeneral_studyType:aorta -logReviewer_imageQualityNumberTest:0').relatedTo(
{ targetElement: currentUser, field: 'logGeneral_sonographerName' }
) %}
<!-- Get average image quality score IF there are any -->
{% if imageQualityScoreAorta|length %}
<!-- Set default numbers -->
{% set additionAorta = 0 %}
{% set countAorta = 0 %}
<!-- Loop -->
{% for entry in imageQualityScoreAorta %}
{% set additionAorta = additionAorta + entry.logReviewer_imageQualityNumberTest %}</td>
{% set countAorta = loop.index %}
{% endfor %}
<!-- Get average image quality score -->
{% set averageValueAorta = (additionAorta / countAorta)|round(1, 'floor') %}
{% endif %}
This is the output:
<!-- Current User Total Studies -->
<table class="table">
<tbody>
<tr>
<td class="c-font-uppercase c-font-bold" scope="row">Aorta</th>
{% if imageQualityScoreAorta|length %}
<td class="c-center c-font-bold">{{ averageValueAorta }}</td>
{% else %}
<td class="c-center c-font-bold">N/A</td>
{% endif %}
</tr>
</tbody>
</table>