How do we change the default currency on freemarker if we have the desired currencycode in string?

StackOverflow https://stackoverflow.com/questions/21331310

  •  02-10-2022
  •  | 
  •  

Question

How do I change the default currency in the currency format of a number in freemarker? I only have the three digit currency code in string format.

Was it helpful?

Solution

Perhaps don't use the ?string.currency -format at all and do the formatting yourself?

For example...

${user.locale.currencySign} ${price.forLocale(user.locale)} 

..

OTHER TIPS

The Freemarker currency format is defined by the Locale. You can change the locale in your Freemarker settings.

You can also manually override the .locale variable in your template using the setting directive.

<#setting locale="en_US">

Documentation:

You could use string formatter options to change the currency symbol like this:

${value?string["¤ ,00;; currencyCode=${currencyCode}"]}

if you have the ISO 4217 code for the currency, or

${value?string["¤ ,00;; currencySymbol=${currencySymbol}"]}

if you have the currency symbol.

Some examples (for value 1234.56):

Parameters Result
CurrencyCode: EUR € 1234.56
CurrencyCode: BRL R$ 1234.56
CurrencySymbol My$ My$ 1234.56

More details in https://freemarker.apache.org/docs/ref_builtins_number.html and https://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top