<p>I'm going to guess something else is wrong in your templates, because all the examples you provided definitely work in Twig. Perhaps you have an error or typo on an earlier line that's preventing your <code>imageHeight</code> calculations from working. I'd also check what <code>imageHeight</code> is set to as that isn't apparent from the snippet you provided; you can check by dumping the value - <code>{{ dump(imageHeight) }}</code>.</p>

<ul>
<li>Here's a TwigFiddle showing how the math does work: <a href="https://twigfiddle.com/522svb" rel="nofollow noreferrer">https://twigfiddle.com/522svb</a></li>
<li>Here are the docs on mathematical operators in Twig: <a href="https://twig.symfony.com/doc/2.x/templates.html#math" rel="nofollow noreferrer">https://twig.symfony.com/doc/2.x/templates.html#math</a></li>
</ul>

CC BY-SA 4.0
2019-08-27T02:08:32.513Z
Yes it was a stupid mistake i made. See my edit.
MrGlasspoole
CC BY-SA 4.0
2019-08-27T01:45:21.803Z
2019-08-27T01:45:21.803Z
Jalen Davenport
<p>I'm trying to calculate some image sizes for Imager.</p>

<p>This works:</p>

<pre><code>{% set imageSizes = [{ height: imageHeight * 4}, { height: imageHeight * 3}, { height: imageHeight * 2}, { height: imageHeight}] %}
</code></pre>

<p>But how do i get halfs?</p>

<p>imageHeight * 2.5, imageHeight * 0.5 or imageHeight / 2 does not work.    </p>

<p><strong>Edit:</strong><br>
It was my own fault.<br>
I checked the array and only saw width's. I set the images sizes in the CP and to:</p>

<pre><code>{% if imageHeight is not empty %}
  {% set imageSizes = [{ height: imageHeight * 4}... %}
{% else %}
  {% set imageSizes = [{ width: imageWidth * 4}... %}
{% endif %}
</code></pre>

<p>I only wrote the half calculation in "if imageHeight" for testing. But the entry i use for testing has only width's...</p>

<templating><craft3>
How to calculate half, third, fourth?
# How to calculate half, third, fourth?

(Asked by: username_0 on 2019-08-26)

I'm trying to calculate some image sizes for Imager.
This works:
{% set imageSizes = [{ height: imageHeight * 4}, { height: imageHeight * 3}, { height: imageHeight * 2}, { height: imageHeight}] %}

But how do i get halfs?
imageHeight * 2.5, imageHeight * 0.5 or imageHeight / 2 does not work.    
Edit:
It was my own fault.
I checked the array and only saw width's. I set the images sizes in the CP and to:
{% if imageHeight is not empty %}
  {% set imageSizes = [{ height: imageHeight * 4}... %}
{% else %}
  {% set imageSizes = [{ width: imageWidth * 4}... %}
{% endif %}

I only wrote the half calculation in "if imageHeight" for testing. But the entry i use for testing has only width's...

**Tags:** templating, craft3

---

## 1 answers

### Answer by username_1 on 2019-08-27. Score: 3

I'm going to guess something else is wrong in your templates, because all the examples you provided definitely work in Twig. Perhaps you have an error or typo on an earlier line that's preventing your `imageHeight` calculations from working. I'd also check what `imageHeight` is set to as that isn't apparent from the snippet you provided; you can check by dumping the value - `{{ dump(imageHeight) }}`.

* Here's a TwigFiddle showing how the math does work: <https://twigfiddle.com/522svb>
* Here are the docs on mathematical operators in Twig: <https://twig.symfony.com/doc/2.x/templates.html#math>

> **Comments:**
> **username_0**: Yes it was a stupid mistake i made. See my edit.  

---

