Getting average of number field values I'm getting close to finishing my first project on Craft CMS but I have one problem.
I'm using number fields to rate items in my entries. It looks like this:

I will have around 6-7 fields and I need to get the average rating of them to display in the front end.
{% set ratingAverage = entry.dizainas + entry.ekranas + entry.veikimas %}

{% set ratingsSum = ratingAverage / 3 %}

&lt;strong&gt;{{ratingsSum|number(decimals=1)}}&lt;/strong&gt;

In fact, some of those fields might be left empty as well so it's needed to skip them.
Can someone help me out with this?
Something like this should work:
{# Setup an arry of the field handles you're interested in #}
{% set fields = ['num1', 'num2', 'num3'] %}

{# set some defaults #}
{% set totalAmount = 0 %}
{% set totalFields = 0 %}

{# loop through the field array #}
{% for field in fields %}

    {# grab the field's value from the entry #}
    {% set value = attribute(entry, field) %}

    {# skip over fields that were left blank, but count fields where 0 was entered #}
    {% if value is not empty and value &gt;= 0 %}

        {# add to the running total and running number of fields with values #}
        {% set totalAmount = totalAmount + value %}
        {% set totalFields = totalFields + 1 %}

    {% endif %}
{% endfor %}

{# do some math #}
{% if totalFields &gt; 0 %}
    {{ (totalAmount / totalFields)|number(decimals=1) }}
{% endif %}