How to Convert a string to number in freemarker template

In your code, you use the closed bracket, so freemarker is evaluating

<#if num >

you should instead use

<#if num gt 100>

This is discussed at the end of this documentation on if statements https://freemarker.apache.org/docs/ref_directive_if.html

The reason this is working for some and not others is because of the parentheses, which is also explained at the bottom of the documentation


I think you can use it like this:string?eval


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.

Tags:

Freemarker