Skip to main content
Solved

How to convert a string to numeric for if statements?

  • March 10, 2024
  • 1 reply
  • 151 views

Forum|alt.badge.img+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

Thanks

Best answer by StefanUE

@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!

View original
Did this topic or the replies in the thread help you find an answer to your question?

1 reply

StefanUE
Expert Problem Solver III
Forum|alt.badge.img+19
  • Champion & Partner
  • 78 replies
  • Answer
  • March 11, 2024

@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!