nikb
I'm new here

setting locale for formatting currencies

Jump to solution

Hi,

in the help section there is a page about formatting numbers and especially handling the placement of the currency symbol. It is great that there is the possibility to use these format strings, but I'm wondering where I can set the currency symbol to use? In other .format methods the locale is settable, but not for CMS_INPUT_NUMBER values. Sure I can write a beanshell script, but is there a easier way?

http://localhost:8000/help/odfs/en/vorlagenentwicklung/vorlagensyntax/datentypen/number/number.html?...

cheers,

Nik

Labels (1)
0 Kudos
1 Solution

Accepted Solutions
Peter_Jodeleit
Crownpeak employee
Crownpeak employee

Re: setting locale for formatting currencies

Jump to solution

There is no special method for writing currencies. But there is no need to use a script, you can handle this in template code with the help of the "class" method:

$CMS_VALUE(class("java.text.NumberFormat").getCurrencyInstance(#global.locale).format(my_number))$

Peter

View solution in original post

0 Kudos
4 Replies
nikb
I'm new here

Re: setting locale for formatting currencies

Jump to solution

I forgot to mention that the locale is also relevant for choosing appropiate signs to group numbers and to separate from factions. e.g. in germany you write: 1.000,98 in US it would be 1,000.98

0 Kudos
Peter_Jodeleit
Crownpeak employee
Crownpeak employee

Re: setting locale for formatting currencies

Jump to solution

There is no special method for writing currencies. But there is no need to use a script, you can handle this in template code with the help of the "class" method:

$CMS_VALUE(class("java.text.NumberFormat").getCurrencyInstance(#global.locale).format(my_number))$

Peter
0 Kudos
nikb
I'm new here

Re: setting locale for formatting currencies

Jump to solution

Ok, thank you, this is helpful. I found this in the documentary and thought this is enough to format currencies:

1) Outputting language-specific currency signs

The symbol ¤ (unicode: #00a4) can be used for this.

Example:

$CMS_VALUE(22.format("0 ¤").convert2)$

As the symbol ¤ is not contained in all character sets and it will possibly not be displayed correctly by the browser, the method .convert2() is used (see data type String). The output is (depending on the selected project language) for example 22 € for German or 22 £ for English.


The symbol ¤ can also be set twice, i.e. ¤¤ (unicode: #00a4#00a4). This will lead to the output of international currency signs (e.g. EUR for German or GBP for English).


so the locale is build up out of the iso codes in the language templates (server settings)? Is it possible to set #global.local at generation time?

0 Kudos
Peter_Jodeleit
Crownpeak employee
Crownpeak employee

Re: setting locale for formatting currencies

Jump to solution

Yes, it's possible to set the locale, but this is not recommended.

Peter
0 Kudos