Renders a value in the currency pattern of the recognized locale.
Attributes | Description |
---|---|
| Automatic/Required Set to |
Usage Notes
The currency
converter renders a value in the currency pattern of the recognized locale. In the following example, no locale is explicitly specified:
<dsp:valueof bean="PriceInfo.amount" converter="currency"/>
If no locale is specified, the locale is determined as follows, in descending order of precedence:
From a
locale
request parameter, either ajava.util.Locale
object or a String that names a locale.From the
RequestLocale
.
A specified locale always has precedence, as in the following example:
<dsp:valueof bean="PriceInfo.amount" locale="en_US" converter="currency"/>
Each locale provides a default setting that determines:
A currency symbol that is supported by ISO Latin-1 (ISO 8859-1)
Separator, such as a comma or period
Format, such as extending the decimal to the tenths position
Tag Converter Extensions: euro and currencyConversion
ATG provides two converters, currencyConversion
and euro
, which let a site display prices in multiple currencies. The classes of these converters extend the currency
tag converter class atg.droplet.CurrencyConverter
:
currencyConversion
(atg.droplet.CurrencyConversionTagConverter
) performs a currency conversion. By default, this converter converts the currency of a specified locale to the currency that is used in the user’s locale.euro
(atg.droplet.EuroTagConverter
) formats a value as Euros if that is the locale’s currency.
These tag converters can take the following attributes:
Attributes | Description |
---|---|
| Valid for This attribute substitutes the specified HTML entity—typically, |
| Valid for |
The following example uses the euro
converter to display a price in Euros. The locale
attribute specifies how to format the output.
<p>Price in Euros: <dsp:valueof locale="en_UK" bean="PriceInfo.amountInEuros" converter="euro" symbol="&euro"/>
In the next example, the dsp:valueof
tag uses the currencyConversion
converter to display the price in British pounds. The exchange rate is obtained from the resource file atg/droplet/ExchangeRates.properties
:
<p>Price in British Pounds: <dsp:valueof locale="en_UK" bean="PriceInfo.amountInEuros" converter="currencyConversion"/>
If locale
indicates a non-euro country such as the United States, the currency converter returns null and the dsp:valueof
tag returns its default value, if any is provided.
The euro
and currencyConversion
converters use the same algorithm as currency
to discover a locale. In the following example, no locale is specified. If the locale is a country that uses the euro, the value of priceInfo.amountInEuros
is converted to the appropriate currency (using the official exchange rates) and displayed in the appropriate format for that locale. If the locale is not a country that uses the euro, the price is displayed as $5.00.
<dsp:valueof bean="priceInfo.amountInEuros" converter="currencyConversion"> Current locale does not use Euros </dsp:valueof>
The currencyConversion
provides a reverse
attribute that converts from a locale-specific European currency (for example, British pounds) into Euros:
<dsp:valueof locale="en_UK_EURO" bean="priceInfo.amountInEuros" converter="currencyConversion" reverse="true" symbol="€"> no price </dsp:valueof>
In this example:
The amount stored in
priceInfo.amountInEuros
is converted to Euros.The
symbol
attribute supplies the HTML entity for displaying the euro currency character.The
locale
attribute is set toen_UK_EURO
value, so the euro value is formatted for the United Kingdom accordingly.