Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Currency.getSymbol() return value (3 letter versus symbol)

807603Dec 13 2007 — edited Dec 14 2007
For a given Currency, how can you return the actual currency symbol and not the 3 letter abbreviation, regardless of the user's locale or default locale? I am aware of other formatting issues related to currency such as fractional digits and separators, but I am just focusing on the symbol here. I have to use Java 1.4. In the examples below the default locale is en_US. In my real application, the currecy code can be any valid one, not just the two I am using here as an example.

Example 1:
double num = 1234.56;
System.out.println(Currency.getInstance("USD").getSymbol() + num);
System.out.println(Currency.getInstance("EUR").getSymbol() + num);
Actual Outputs:
$1234.56
EUR1234.56

Example 2:
double num = 1234.56;
NumberFormat formatter = NumberFormat.getCurrencyInstance();
Currency usd = Currency.getInstance("USD");
Currency eur = Currency.getInstance("EUR");
formatter.setCurrency(usd);
System.out.println(formatter.format(num));
formatter.setCurrency(eur);
System.out.println(formatter.format(num));
Actual Outputs:
$1,234.56
EUR1,234.56

Desired Outputs (symbol displays for both):
$1,234.56
�1,234.56

Any suggestions? Thank you.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 11 2008
Added on Dec 13 2007
8 comments
385 views