Convert number to 2 decimal places without using any function

//Info: CDUS-1294

We have met a scenario where we need to set the value to 2 decimal points, which is populated after a calculation.

<#assign crt= item.quantity?number / item.custcol_jj_carton_number?number>
<td colspan="2" style="border-width: 0.2pt;">${crt?string["#,##0.00"]}</td>

We can do the same by defining a function,

<#function toDecimal value showSymbol=false>
          <#if value?is_number>
          <#local retval = 0>
          <#local retval = value?string["#,##0.00"]>
         
          <#return retval>
          <#else>
          <#return value>
          </#if>
        </#function>

<td colspan="2" style="border-width: 0.2pt;">${toDecimal(value)}</td>

Leave a comment

Your email address will not be published. Required fields are marked *