How to Convert a string to number in freemarker template

Mady picture Mady · Jun 7, 2012 · Viewed 54.5k times · Source

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?

Answer

Mady picture Mady · Jun 7, 2012

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.