Custom Function for German Currency Formatting in Freemarker

Freemarker, a popular template engine, offers flexibility in formatting data for various purposes, including currency representation. However, sometimes standard settings may not suffice, especially when dealing with specific localization requirements such as German currency formatting. In this article, we’ll explore a custom function created in Freemarker to meet German currency formatting standards.

<?xml version=”1.0″?><!DOCTYPE pdf PUBLIC “-//big.faceless.org//report” “report-1.1.dtd”>

<pdf>

<head>

<#function currencyFormat amount1>

   <#assign amount = amount1?number>

   <#local formattedAmount = amount?string(“0.00”)>

   <#local parts = formattedAmount?split(“.”)>

   <#local decimalPart = parts[1]>

   <#assign reversedString = reverseString(parts[0])>

   <#assign chunkedReversedIntPart = reversechunk(reversedString)>

     <#local numbesetting = chunkedReversedIntPart+”,”+parts[1]>

   <#if amount < 0>

       <#return “(” + numbesetting + “)”>

   <#else>

       <#return numbesetting>

   </#if>

</#function>

<#function reverseString str>

   <#assign x = ”>

   <#list str?split(“”) as char>

       <#assign x = char + x>

   </#list>

   <#return x>

</#function>

<#function reversechunk str1>

   <#assign z = ”>

   <#list str1?matches(‘.{0,3}’, ‘s’) as char1>

       <#assign z = reverseString(“.”+char1) + z >

   </#list>

   <#assign z = z?string?remove_beginning(“.”)>

     <#assign z = z?string?remove_ending(“.”)>

   <#return z>

</#function>

</head>

<body footer=”nlfooter” footer-height=”20pt” padding=”0.5in 0.5in 0.5in 0.5in” size=”Letter”>

  <#assign y = 1234561234567890123456789>

 <p>${currencyFormat(y)}</p>

</body>

</pdf>

Leave a comment

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