Money formatting in Flow email

I’ve been working on a Flow internal email, and can’t get the cents on the product price to show up in correct money format, with 2 digits after the decimal. Many of the products are even-dollar amounts ($25.00 for example) but are coming through in the email with just a single digit ($25.0).

If I pipe the variable for the price through “|money” the run fails with the error: “The rendered liquid was too large or had too many assignments”

{{lineItems_item.name}} at ${{lineItems_item.variant.price |money }} x
          {{lineItems_item.currentQuantity}}

I’ve sampled many variables, with “money” and “decimal” types from the variables list and every one I’ve tried performs the same way. Is there some way to format this to correctly show both digits to the right of the decimal in the price amount?

Thanks in advance for any help with this!

2 Likes

Hi @B2C-YYC

Could you try this code and check if it works?

{{lineItems_item.name}} at ${{lineItems_item.variant.price | money_without_trailing_zeros }} x {{lineItems_item.currentQuantity}}

Hi @Dan-From-Ryviu , thanks for responding. I tried your code to confirm that it also doesn’t work. I don’t think it’s possible to pipe variables through the filters used for on-site liquid.

Flow does not use the same liquid filters as themes. It uses this library https://shopify.github.io/liquid/. So that | money_without_trailing_zeros does not work

Thanks @paul_n - I reviewed all the available filters, and thought “round: 2” might work - tried this:

{{lineItems_item.name}} at ${{lineItems_item.variant.price | round: 2 }} x {{lineItems_item.currentQuantity}}

but I’m still getting a single cent digit when I retry the run. Do you have any other formatting suggestions to tackle this?

I don’t like it, but I know this works:

{% assign money = order.currentTotalPriceSet.shopMoney.amount | split: "." %}{% assign cents = money | last %}{% if cents == "0" %}{{ money | first }}.00{% else %}{{order.currentTotalPriceSet.shopMoney.amount}}{% endif %}

Thanks @paul_n - yep, that isn’t pretty but it works!

I updated for the line items:

{% assign money = lineItems_item.variant.price | split: "." %}{% assign cents = money | last %}{% if cents == "0" %}{{ money | first }}.00{% else %}{{lineItems_item.variant.price}}{% endif %}

and used your suggestion for the order total (updated money to totmoney in case of conflict), and still found a case where the order total ended in .90 and shows .9 still, of course, but this is light years better for the even dollar amounts. Thank you!

Any chance a number padding filter or money filter might be added someday which would catch all these missing zeroes?

1 Like

Yeah it’s possible. I don’t have a timeline for this though.

1 Like