Currency formatting in the Aurora sample store
The Aurora sample store uses the JSTL number format <fmt:formatNumber>
) in
JSP files in combination with the shopper's locale setting to format currencies. As a result,
customizing the currency format for Aurora involves changing the tagging in many JSP files.
The following code snippet is an example of the JSTL implementation that sets the currency format on the shopping cart page of the Aurora sample store:
<span class="price">
<fmt:formatNumber var="formattedUnitPrice" value="${orderItem.unitPrice}" type="currency"
maxFractionDigits="${env_currencyDecimal}" currencySymbol="${env_CurrencySymbolToFormat}"/>
<c:out value="${formattedUnitPrice}" escapeXml="false" />
<c:out value="${CurrencySymbol}"/>
</span>
The Aurora sample store also uses the Utils.formatCurrency
JavaScript function
to format currencies. The Utils.formatCurrency
function is an extension of the
formatCurrency
function from the Globalize library, which is a JavaScript library
for internationalization and localization. The function uses the shopper's locale setting, so that
the locale parameter does not have to be passed.
Utils.formatCurrency("123.4", { minimumFractionDigits: 2, maximumFractionDigits: 2, currency: "USD" })
Where
the following parameters are accepted:- amount
- String: The currency amount.
- options
- Object: Include optional options, such as currency, minimumFractionDigits, or maximumFractionDigits.
Currency customization options
If a shopper is viewing a store with US prices in the French language, the JSTL implementation displays the price according to the currency format for the French locale (fr_FR):1 800,00 $
- Pass the
pattern
attribute of the<fmt:formatNumber>
tag to all JSP files that display prices in the store. - Implement a custom tag. This option still requires an update to all JSP files that display prices. However, if you want to change the pattern in the future, you can change the custom tag itself rather than updating all the JSP files again.