Solved

How to set currency to automatically reflect up to 2 decimal spaces ($X.XX)

  • 26 March 2021
  • 8 replies
  • 3180 views

Badge +2

When showing an order confirmation, is there a way to automatically have the system default to two decimal places? 

 

For example, if the total of an order is $44.80, the data comes in as $value: 44.8 (indicated by the orange arrow in image).

However in the top of preview function, it states:

John Smith

Placed Order for $44.80

(indicated by green arrow in image)

So, when I go to preview the image using this data, it doesn’t automatically format to two decimal places like US currency should and ends up leaving off the zero that should be in the second decimal place. (red arrow in image)

What I want to know is how can I have any dollar amount within an automated email that uses data from an ecommerce store to automatically format to show up to two decimal places. Meaning it will add in the zero if a number is not already provided. 

 

Additionally, I will need to know if there is a specific code to use for Shopify vs WooCommerce, as I have two different stores (and Klaviyo accounts) and need to have this feature used for both types of integrations. 

 

I’ve searched the help desk articles high and low and can’t find any information that addresses this issue. Any help or guidance is greatly appreciated!!!!

 

 

icon

Best answer by Bobi N. 26 March 2021, 09:14

View original

8 replies

Userlevel 7
Badge +42

@BC_EmailMarketing

You can do this with floatformat for example {{ event|lookup:'$value'|floatformat:2 }}

Badge +2

Thanks! Do you know if it works for both Shopify and WooCommerce? I’ve realized how sometimes a setting will work for one and not the other. 

 

Userlevel 5
Badge +25

Hey @BC_EmailMarketing! The solution Bobi suggested will work on any number field, no matter where it comes from.

Badge +2

Thank you! @elisegaines @Bobi N. 

Badge +2

The snippet/code with floatformat does not work for me. I have shopify. Can someone tell me if this was changed for the new editor? Any other suggestions?

Userlevel 7
Badge +60

Hey @C B,

The floatformat:2 variable filter that @Bobi N. previously provided should work in both the classic and new editor.

There’s been no changes to the underlying django framework that both editors use. You can also find a glossary of some of our most commonly used filters and how to use variable filters from our Glossary of variable filters and How to use filters to customize variables Help Center articles.

David

Badge

I get the same prolem. I tried {{ event|lookup:'$value'|floatformat:2|default:'0' }} but it doesn't work. I'm using WooCommerce. By the way, I also want to add currency prefix (ex: $150.95). Can someone please help me? 

Userlevel 7
Badge +60

Hey @Karina,

That code you mentioned you’ve tried should work. If not, I would suggest reviewing how you’ve put the code into your email template. A common mistake many people make is incorporating some additional formatting when copy and pasting the code into the template. Another mistake I see often is using this code within a table block set to dynamic.

Additionally, to automatically include your account’s currency prefix, you can use the {% currency_format %} syntax as mentioned in our Catalog lookup tag reference Help Center article. This means you can use {% currency_format event|lookup:'$value'|floatformat:2 %} which will not only include the account’s currency prefix, but also include 2 decimal places for the price. 

David

Reply