'How to convert numbers to be a comma separated value in Klaviyo

I have these dynamics variables which has a number.

I.E) 1, 10, 350, 1200 or 12500, etc.

On Klaviyo I want to format these numbers to be comma separated if it's over 1 thousand.

I.E) 
      1200 -> 1,200
     13499 -> 13,499
   1000000 -> 1,000,000

If it's less than 1 thousand, there are no commas

     5 -> 5 
     60 -> 60
     100 -> 100

I tried looking for a Klaviyo Filter here https://help.klaviyo.com/hc/en-us/articles/360058466052-Glossary-of-Variable-Filters but there are none specific for converting number to comma separated thousands.

I can't seem to find the right filter and I'm not sure how to write a custom one to do this.

How would we do this in Klaviyo?

Thank you!



Solution 1:[1]

Not sure if Klaviyo intends this to work, but surprisingly, in my test it did!

Klaviyo's templating engine, as you pointed out, is based on Django's Template system - but Klaviyo can determine what functionalities are enabled (or disabled) or install custom ones. One of these filter libraries is called "django.contrib.humanize" which adds these "human touch" to data.

To do this, you first load the library like this: {% load humanize %}

Then you can use the filter intcomma like this: {{ your_variable|intcomma }}

Testing this with:

{{ 1000000|intcomma }}

Yields: 1,000,000

Try it and let us know if it works!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cray