Skip to main content
Problem Solver I
March 10, 2024
Solved

How to convert a string to numeric for if statements?

  • March 10, 2024
  • 1 reply
  • 325 views

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

    This topic has been closed for replies.
    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!

    1 reply

    StefanUE
    Expert Problem Solver III
    StefanUEAnswer
    Champion & Partner
    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!

    Get in touch at https://www.linkedin.com/in/stefan-milicevic-706331137/