i18n Currency issue

B

Bobby Quinne

Hi there,

I have been having an issue attempting to retrieve the currency symbol
from the currency code.

Basically I am just given the currency code(EG: USD) and I can expect
multiple currency codes to be supplied.
Using :
java.util.Currency.getInstance("USD").getSymbol();

returns USD. Not what I want.

Using :

java.util.Currency.getInstance("USD").getSymbol(java.util.Locale.US);
does return $ which is what I want.

In this instance I am clearly explicitly using Locale.US. Now from
what I can see there is no easy way to get the Locale from the
currency code.

What I have tried :

1. Coded a static lib with an array of the predefined Locales in
java.util.Locale. It does work and return me the symbol but there are
less than 10 predefined Locale(others in there are for Language). Also
adding new definitions to the array is not appealing.

2. Tried jscience-4.3.1 but from the examples
http://jscience.org/api/org/jscience/economics/money/package-summary.html
it looks like the symbol needs to be setup in code. Same issue as the
above having to add definitions and recompile if new additions come
along.

Is there something glaringly obvious I am missing?
Is there perhaps a framework that makes this easy?

Currently I am looking through the JRE and seeing where the resource
data is. Java tutorial makes mention of ResouceBundles for i18n.

Many thanks to any assistance lended.
 
G

GArlington

Hi there,

I have been having an issue attempting to retrieve the currency symbol
from the currency code.

Basically I am just given the currency code(EG: USD) and I can expect
multiple currency codes to be supplied.
Using :
java.util.Currency.getInstance("USD").getSymbol();

returns USD. Not what I want.

Using :

java.util.Currency.getInstance("USD").getSymbol(java.util.Locale.US);
does return $ which is what I want.

In this instance I am clearly explicitly using Locale.US. Now from
what I can see there is no easy way to get the Locale from the
currency code.

What I have tried :

1. Coded a static lib with an array of the predefined Locales in
java.util.Locale. It does work and return me the symbol but there are
less than 10 predefined Locale(others in there are for Language). Also
adding new definitions to the array is not appealing.

2. Tried jscience-4.3.1 but from the exampleshttp://jscience.org/api/org/jscience/economics/money/package-summary....
it looks like the symbol needs to be setup in code. Same issue as the
above having to add definitions and recompile if new additions come
along.

Is there something glaringly obvious I am missing?
Is there perhaps a framework that makes this easy?

Currently I am looking through the JRE and seeing where the resource
data is. Java tutorial makes mention of ResouceBundles for i18n.

Many thanks to any assistance lended.

My guess that your problem is here:
getSymbol

<extract from java docs>
public String getSymbol()
Gets the symbol of this currency for the default locale. For example,
for the US Dollar, the symbol is "$" if the default locale is the US,
while for other locales it may be "US$". If no symbol can be
determined, the ISO 4217 currency code is returned.
Returns: the symbol of this currency for the default locale
</extract>
the method returns the symbol [if found] for DEFAULT locale, it
happens to be the one which your server is configured with, unless you
change it at run-time.
Not all locales (countries) will use the same symbol for the same
currency, for this reason locale is NOT set in the instance of
currency...
 
B

Bobby Quinne

Is there a way you can just hang on to the Locale up front?  

I never receive the local, basically a huge xml blob is suck from
db(awful) where there is financial data on financial movements.

My co-conspirator might be onto something tho. Just need to test it
and will report back
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top