Displays a numeric value as a currency amount, formatting it based on the locale
Class Name |
|
---|---|
Component |
|
Required Input Parameters
currency
The numeric value to format. This value can be expressed as either a java.lang.Number
or a String.
Optional Input Parameters
locale
The locale that determines the format of the currency amount. This value can be either a java.util.Locale
object or a String that represents a locale (such as en_US
). If omitted, the Oracle Commerce Platform uses the default locale supplied in the request object.
euroSymbol
Lets you format the currency amount with a euro symbol even if your encoding does not support it; the character set ISO 8859-1 (Latin-1), for example, does not include the euro character. For the value
attribute, specify the HTML code for the ASCII euro symbol as shown here:
<dsp:param name="euroSymbol" value="€"/>
You must use the valueishtml
attribute with a <dsp:valueof>
tag in the formattedCurrency
parameter so the Oracle Commerce Platform displays the HTML euro symbol. Without using this attribute, the Oracle Commerce Platform displays the value literally rather than process it as HTML code.
<dsp:oparam name="output">
<dsp:valueof param="formattedCurrency" valueishtml="true">no
price</dsp:valueof>
</dsp:oparam>
Output Parameters
formattedCurrency
The formatted currency value.
Open Parameters
output
The output to render.
Usage Notes
CurrencyFormatter
takes a numeric value and displays that value as a currency amount, formatting it based on the locale. The formatting includes the currency symbol, the placement of the symbol, and the delimiters used. For example, if the value passed in is 20000, and the locale is en_US
, the servlet bean formats the value as $20,000.00; if the locale is de_DE
, the servlet bean formats the value as 20.000,00 DM.
Example
In this example, CurrencyFormatter
renders the value 1059 in the appropriate format. The specified value is saved to the priceToDisplay
parameter, which is processed through CurrencyFormatter
. CurrencyFormatter
applies the locale provided by OriginatingRequest
component to the priceToDisplay
value and saves it to the formattedCurrency
parameter, which is displayed in the JSP. If the locale in OriginatingRequest
is set to en_US
, the rendered value is $1059.00
.
<dsp:setvalue param="priceToDisplay" value="1059"/> <dsp:droplet name="/atg/dynamo/droplet/CurrencyFormatter"> <dsp:param name="currency" param="priceToDisplay"/> <dsp:param name="locale" bean="/OriginatingRequest.requestLocale.locale"/> <dsp:oparam name="output"> <p>Current price: <dsp:valueof param="formattedCurrency"/> </dsp:oparam> </dsp:droplet>
The second example shows how to use the euroSymbol
parameter with the valueishtml
attribute of the <dsp:valueof>
tag to display an amount with the euro symbol. This code displays the following value:
3,99 €
€€€€€€€
<dsp:droplet name="/atg/dynamo/droplet/CurrencyFormatter"> <dsp:param name="currency" value="3.99"/> <dsp:param name="locale" value="de_DE_EURO"/> <dsp:param name="euroSymbol" value="€"/> <dsp:oparam name="output"> <dsp:valueof param="formattedCurrency" valueishtml="true">no price</dsp:valueof> </dsp:oparam> </dsp:droplet>