File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Getting currency symbols Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting currency symbols" Watch "Getting currency symbols" New topic

Getting currency symbols

Rich Davies

Joined: Jul 31, 2006
Posts: 2

This is my first attempt at playing with currencies in Java and I'm struggling with a problem. Basically I have a page that displays a list of available currencies. This list is derived from a database table which has the currency names and ISO 4217 currency codes (i.e. USD, GBP etc). The list is created by selecting all of the currencies from this table and loading them into a list of java.util.Currency objects, where each Currency object is created like so:

I then iterate over that list calling the Currency.getSymbol() method for each currency to display the appropriate symbol for each one. The problem is that it doesn't. All that gets displayed is the currency code for each currency, except for Euros and GBP where the appropriate � or � symbol is displayed. I've read around and it appears that this is because my default Locale is set to the UK and indeed when I change the Locale to the US for example, then USD appear as $ and Euro's don't!

So what I would like to know is is it possible in java to get a currency's symbol using only a currency code and without having to change the default Locale? Or am I better off just adding another column to my database and storing symbols in there?


Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Have you read the documentation for the getSymbol(Locale) method? It tries to explain why you are seeing what you are seeing.
I agree. Here's the link:
subject: Getting currency symbols
It's not a secret anymore!