Search code examples
freemarker

How to Convert a string to number in freemarker template


I want to convert a string to number in freemarker. I want to put some conditional check based on the value of the number. ?number doesn't seems to work.

Any suggestions?


Solution

  • Sorry, ?number does work fine. I was not able to compare the converted number with another number.

    This didn't work for me:

    <#assign num = numString?number>
    
    <#if num > 100>
    </#if>
    

    When I enclosed (num > 100) inside the brackets it worked:

    <#if (num > 100)>
    </#if>
    

    Since the comparison was not working, I was assuming that conversion was not happening. My bad.