Forum Discussion

peterlu's avatar
peterlu
Champion
8 years ago

number format

Hi,   For number 1000, US is using 1,000 and EU is using 1.000 In freemarker, we can do things like ${count?string(",##0")} for US But, I want to format the number based on user's language settin...
  • TariqHussain's avatar
    8 years ago

    peterlu - There is no built-in function for that. However, you can create a switch case by checking the user language. 

     

    <#assign userlang = rest("/users/id/${user.id}/settings/name/profile.language").value>
    <#assing count = 1000 />
    <#switch userlang>
      <#case "de">
                <#-- code --> 
        <#break>
      <#case "es">
                <#-- code --> 
         <#break>
      <#case "fr">
                 <#-- code --> 
         <#break>
      <#case "ja">
                <#-- code --> 
         <#break>
      <#case "ko">
               <#-- code --> 
         <#break>
      <#case "ch">
                <#-- code --> 
        <#break>
      <#case "it">
               <#-- code --> 
        <#break>
      <#default>
             <#assign formatedNumber = count?string(",##0") />  
    </#switch>
    
    ${formatedNumber}