Ashish Mittal
Ashish Mittal

Reputation: 141

Convert numerical value to string in Freemarker

I am trying to write a freemarker template in which one field value is passed as numeric but I want to print it as a string. Currently I am fetching values from a JSON.

Freemarker is formatting that number which is not required in my case. E.g. if I am passing a number as shipmentId: 23452742 freemarker is converting it into 23,452,742

${shipment.shipmentId}

How to convert a numeric value to string or stop freemarker formatting for one particular field? Any help would be appreciated.

Upvotes: 3

Views: 16660

Answers (2)

Ashish Mittal
Ashish Mittal

Reputation: 141

The above suggestion didn't worked for me. It may be due to some freemarker version issue. I tried :

<#setting number_format="0" />
   ${(shipment.shipmentId)}  
<#setting number_format="" />

to stop formatting for a specific block.

Thanks for the help folks.

Upvotes: 0

obourgain
obourgain

Reputation: 9336

You can use the ?c builtin:

${shipment.shipmentId?c}

This built-in converts a number to string.

Upvotes: 7

Related Questions