Round transformed result to 2 decimal places

Just went through the Right click Currency Conversion tutorial. Awesome extension and can’t wait to use it when I visit Portugal this summer.

The only problem is the output is too verbose. For example, converting $5,964 to euros yields “5372.9729729729725”. I want to round the result to 2 decimal places. Is there anyway to do that?

Hi Johnny - you can use nunjucks to perform rounding with this syntax

{{ 5372.9729729729725 | round}}

or if you have a variable

{{ @myVar | round}}

Specifically to round to 2 decimal places you can use this:

{% set num = @myVar.split('.') %}
{{num[0]}}.{{num[1] | truncate(2, true, "")}}

@orlando this worked, thanks!

Looks like you can pass the number of decimals you want to round (nunjucks docs):

{{ @myVar | round(2) }}

Nice, yeah that is pretty cool because it’s out of the box - I definitely over-engineered my answer woops!