Customizable Filters

Hi SF community!

I am trying to customize the filters being used upon printing a value in our templates to give the flexibility of adding decimals to printed numbers. In other words, we were hoping to have a case statement referring to a dropdown question asking “How many decimals do we want in the output of the number” and the number of decimals change according to the answer. My originally thought was printing: {{ number_variable | currency_dc:XXXX }} with XXXX = a variable from 1-5 depending on the case statement.

Is it possible to assign a variable to a filter? Or is there another efficient way to do this for a large set of numbers without writing lengthy IF statement code for each scenario?

Thanks!

Hi Alexander,

Welcome to the silverfin community!

It is possible to make the XXXX variable. Consider the following code:

{% assign amount = 5.10005 %}

{% assign number_of_decimals = 1 %}

{{ amount | currency_dc:number_of_decimals }}

In this case the output is 5.1.

Regards,

Michiel

Michiel,

This was perfect - thank you for the solution! Works perfectly.

Alex Krause