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 settings. Is there a Lithium built-in function to format the number based on the user language setting?

eg. ${utils.numbers.some_format_function($count)}

 

Peter

  • 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}

2 Replies

  • 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}