- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
setting locale for formatting currencies
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?
cheers,
Nik
- Labels:
-
Developers
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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))$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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))$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, it's possible to set the locale, but this is not recommended.

