Mathematical operations and Twig variables Is it legal to do this in a node template with Drupal 8?

{% set percentVariable = content.field_my_customfield.0 * 100 / content.field_my_second_customfield.0 %}


which will be output like this

&lt;div style="width:{{ percentVariable }}{{'%'}}"&gt;&lt;/div&gt;


Both fields deliver integer values to that variable

Is there any major syntax error or misunderstanding in doing so?
Yes, it is legal to do mathematical operations in Twig (and in PHP as well). The issue you have is you are trying to calculate render arrays, which doesn't work, no matter which programming language you use. You need to do this on the field values. For example the first value you are looking for:

in PHP:

$value = $node-&gt;field_my_customfield-&gt;value;


or in Twig:

{% set value = node.field_my_customfield.value %}


This code should work then in Twig:

{% set percentVariable = node.field_my_customfield.value * 100 / node.field_my_second_customfield.value %}
&lt;div style="width:{{ percentVariable|round }}%"&gt;&lt;/div&gt;