Search the FirstSpirit Knowledge Base
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
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))$
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
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))$
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?
Yes, it's possible to set the locale, but this is not recommended.