Solved

Help! - floatformat:0 is not working with catalog price to show no decimal points


Badge +1

Hi there,

I’ve searched across all the forum posts and on google but I cannot seem to get this working.

I would like to display the catalog price as a whole number (with no trailing decimals) like this:

 

I have tried using floatformat:0 and floatformat:-2 but it doesn’t do anything it seems. This is my code:

“ Price: {% catalog 6957868023984 %}{% currency_format catalog_item.metadata.price|floatformat:0 %}{% endcatalog %}”

And this is the result I’m getting:

Your help is much appreciated! Thank you

icon

Best answer by retention 6 July 2022, 23:23

View original

4 replies

Userlevel 7
Badge +58

Hi there @JasonEdward,

Welcome to the Community.

Quick question, are you trying to set this up for a product block? If so, there currently is no way to edit product blocks to have no decimals. You can only edit the price if you choose the "Select from Catalog" option in the Product Block. If you "Populate from the feed", it will simply display what's listed in your store with the decimals. Selecting from the Catalog provides you with the option to change the name or price as exactly as you would want to show. Note that the event variable is pulling from the event data, not from the catalog.

 

You can also learn more here: Apply a Filter to a Variable

 

Thanks,

Alex

 

Badge +1

Hi @alex.hong , thank you for your reply and insight.

 

To answer your question:

I am trying to find the price of a specific product in the catalog and display it in text. I am not using a product block.

What I discovered is that I can use "Select from Catalog" to find the ItemID, but I don’t need the product section as it still shows unnecessary data. The whole point is that this is meant to be dynamic so the price can change in future.

 

I was able to get the pricing info that I needed by using the code: {% catalog ItemId %}{% currency_format catalog_item.metadata.price|floatformat:0 %}{% endcatalog %}

and display it in the plain text with no issue.

But this is where I’m stuck, because despite my floatformat:0, it still shows the decimals.

 

As far as I know I am not using the event variable.

 

Is there maybe a different variable I need to use?

 

Thanks again,

Jason

 

Userlevel 7
Badge +57

Hi @JasonEdward, welcome to the community.

I think the “Currency Format” function will always force it to be trailing double digit and ignore the floatformat filter.  If you don’t mind adding in the dollar sign outside of the variable, see if this works:

{% catalog 6957868023984 %}
Price: ${{ catalog_item.metadata.price|floatformat:0 }}
{% endcatalog %}

 

Badge +1

@retention amazing! That worked. Thank you so much

Reply