Skip to main content
Contributor I
January 26, 2022
Solved

Is there a filter available to Format an item price to include a comma in Klaviyo?

  • January 26, 2022
  • 12 replies
  • 2288 views

Hi,

 

We struggle to find a way to format item price values with comma every three digits (before the float point).

 

For example:

  • 10283 → should become 10,283.00
  • 2938449 → should become 2,938,449.00

Is there a way to do such format, or is it something can’t be achieved with current django string and float format functions in Klaviyo? knowing that django’s intcomma allows such formatting but apparently the function is not supported in Klaviyo.

 

Thanks,

Loai

    This topic has been closed for replies.
    Best answer by Taylor Tarpley

    Hi @loai.taha

     

    Thank you for brining this to my attention and attaching a screenshot! It was very helpful to bring to my colleagues and discuss further. After more investigation, it does seem like this is a limitation of our editor. You could use this filter to accomplish what you’re looking for, however this filter only works as long as the numbers are six digits and below:

    {% with val=event|lookup:'$value' %} {% if val|where:'val > 999' %} ${{ val|stringformat:"d"|slice:":-3" }},{{ val|stringformat:"d"|slice:"-3:" }} {% else %}{{ val|stringformat:"d" }}{% endif %} {% endwith %}

     

    However, I am looping in more specialist and will try to discover if there is another workaround for you! Very sorry for the inconvineince, but thank you for bringing this to the Community’s attention! 

    -Taylor 

    12 replies

    Contributor I
    February 1, 2024

    Hi,

    In the meantime I have found the filter that accomplishes the desired effect. As stated in the Klaviyo docs most Django filters are supported and as of Django 3.2:

    The g suffix to force grouping by thousand separators was added to floatformat.

    https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#floatformat

    So, all that’s needed is to run your value through the following filter:

    {{ val|floatformat:”2g” }}

    This simplifies things considerably.

    You are a life saver!!! Thank you so much

    DanielD
    Contributor II
    Contributor II
    May 29, 2024

    ...

    Here is the code I used according to django’s docs: {{item.Price|intcomma}}

    ...

    Hi, just wanted to add, in case someone was trying to add commas to a non-price number, the |intcomma filter works if you first load the humanize django library. So, for example, instead of…

    {{ person|lookup:'LoyaltyPoints'|intcomma }}

    … you can use…

    {% load humanize %}{{ person|lookup:'LoyaltyPoints'|intcomma }}

    More on the django.contrib.humanize library here.