How to convert a string to numeric for if statements?

  • 10 March 2024
  • 1 reply

Badge +2

I’m trying to have some logic for the product prices. 

I tried removing the dollar $ sign but it’s still evaluating it as a string it seems. I also couldn’t find a function to convert a string to numeric?

For example event.Price = $359 will trigger the first if statement. 

{% if event.Price|find_replace:"$| " >= 400 %}

$50 discount
 {% elif event.Price|find_replace:"$| " >= 150 %} 

$30 discount



Best answer by StefanUE 11 March 2024, 07:46

View original

1 reply

Userlevel 5
Badge +18

@AndrewBu hey, thanks for your question!

A similar question was actually previously asked and answered in THIS ARTICLE.

Basically, you need to find the appropriate line of code that’s pulling your price information on the integration level, and then change that so it says:
Price: {{ product.price|divided_by:100.0|json }}

This will then convert the way the price is pulled in from a string (which it needs to be so the currency symbol can be displayed) into a numerical value (which will enable you to search and filter based on the value).

Happy to chat further!