Mathematical operations and Twig variables
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;