Question

Photo of Hatim Motiwala

0

How to use Currency Type in Lava Calculations

I am not able to use Currency Type in Lava Calculations anymore, it used to work before. I am running Rock version 12.6

For example if I have a global attribute "UnitPrice" defined as Currency Type with a value of $2.50 then the lava below does not work as expected.

{% assign unitPrice = 'Global' | Attribute:'UnitPrice' %}

Total Price = {{ unitPrice | Times: 2 }}

Actual Result:

Total Price = $2.50 $2.50

Expected Result:

Total Price = $5.0

If I apply  | AsDecimal filter first then the result is just blank.

Any ideas on how to fix this ?

  • Photo of Daniel Hazelbaker

    2

    Hi Hatim, I would recommend using the "RawValue" option with the Attribute Filter. That should give you the value without the currency symbol.

    {% assign unitPrice = 'Global' | Attribute:'UnitPrice','RawValue' %}
    Total Price = {{ unitPrice | Times: 2 }}

  • Photo of Thomas Stephens

    0

    Unit price is something that your organization added as a global attribute. We will need some more information to help you. Is unit price a Currency field type?

    The first thing I would try is:

    {% assign unitPrice = 'Global' | Attribute:'UnitPrice' | AsInteger %}