I want to place correctly the $ symbol, either as a prefix or suffix, depending on locale using the MessageFormat class, but without success so far. I need to localize the currency symbol placement, but not the symbol itself.
In my message I use:
The car cost is {0, number, currency}
and I create an instance of MessageFormat calling:
MessageFormat messageFormat = new MessageFormat(msg, locale);
The result is that currency symbol is placed correctly but it has been also changed depending on used locale. For locale en_us I get $, for locale pl_pl I get zł.
So the question is, how to tell MessageFormat to use always the same currency symbol ($ in my case) but putting it (as the prefix or suffix) depending on locale?
Based on MessageFormat manual looks like that {0, number, currency} is formatted using NumberFormat.getCurrencyInstance(getLocale()), so I wonder if it is possible at all.
Thank you in advance for your help.
Turns out that it is possible. The CurrencyAmount object, set up as the USD currency, should be passed as an argument to the format method of MessageFormat class.