Skip to content

Magento 2 – email template variable formatting

I’m trying to format:

{{var order.getBaseTotalRefunded()}}

or

{{var creditmemo.grand_total}}

The output of both of these is:

261.6700

I read that the template editor allows Twig filters (https://twig.symfony.com/doc/2.x/filters/index.html), but I have tried a lot of them an none of them worked.

I’m trying to cut the number down to:

261.67

I have tried:

{{var order.getTotalRefunded() | number_format(2, '.', ',') }}
{{var order.getTotalRefunded()| format_number({fraction_digit: 2}) }}
{{var creditmemo.grand_total|raw|float|round: '2' }}

Any ideas how to get this to work correctly?

Thanks!

UPDATE:

Found a workaround and just hardcoded this stuff into the PHTML template, but would be still nice to know since Magento documentation has 0 information on this topic.