RayLeong
asked on
Currency Symbol
I am using JDK1.4. When run the following code
> Locale sg = new Locale("en", "SG");
> System.out.println(sg.getL anguage() + " " + sg.getCountry() + " " + NumberFormat.getCurrencyIn stance(sg) .format(10 00000));
I get
> en SG SGD1,000,000.00
Actually what I wanted is S$1,000,000.00
Is it possible to configure it to use S$ instead of SGD. I understand that currency code is used when the symbol is not available. Is there a way to plugin the setting I want to specific locale?
> Locale sg = new Locale("en", "SG");
> System.out.println(sg.getL
I get
> en SG SGD1,000,000.00
Actually what I wanted is S$1,000,000.00
Is it possible to configure it to use S$ instead of SGD. I understand that currency code is used when the symbol is not available. Is there a way to plugin the setting I want to specific locale?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Well I tried out the Currency class, with quite disappointing results. Most symbols were just codes. There were a few that were correct (eg. the sterling symbol was correct for UK pounds), however the US Dollar symbol was not shown. I just got USD.
Here is the code I used. It might be worth trying on your system to see what you get (I had 134 locales, just like savalou).
Other than that I'd go along with savlou's "Campaign for the recognition of the Singapore Dollar" ;-) and implement his suggestion.
If you do run the following code, I'd be interested to know if you got the symbol (or even the locale).
import java.util.*;
public class CurrencyLocales
{
public static void main(String[] args)
{
Locale[] locales = Locale.getAvailableLocales ();
System.out.println("Availa ble locales = " + locales.length);
for (int i = 0; i < locales.length; i++)
{
System.out.print("Locale = " + locales[i].toString());
try
{
Currency currency = Currency.getInstance(local es[i]);
System.out.println(" Currency = " + currency.getSymbol());
}
catch (IllegalArgumentException iae)
{
System.out.println(" Currency = Invalid locale");
}
}
}
}
Here is the code I used. It might be worth trying on your system to see what you get (I had 134 locales, just like savalou).
Other than that I'd go along with savlou's "Campaign for the recognition of the Singapore Dollar" ;-) and implement his suggestion.
If you do run the following code, I'd be interested to know if you got the symbol (or even the locale).
import java.util.*;
public class CurrencyLocales
{
public static void main(String[] args)
{
Locale[] locales = Locale.getAvailableLocales
System.out.println("Availa
for (int i = 0; i < locales.length; i++)
{
System.out.print("Locale = " + locales[i].toString());
try
{
Currency currency = Currency.getInstance(local
System.out.println(" Currency = " + currency.getSymbol());
}
catch (IllegalArgumentException iae)
{
System.out.println(" Currency = Invalid locale");
}
}
}
}
ASKER
Other than programming, is there any way to plugin a class, property file to overwrite the default currency symbol used for a particular locale. Is the Currency or Locale design to take in other class, property file created by developers.
I've quickly searched around a few times today, but I can't find an easy way to do this. I think savalou has provided the best answer for this problem.
Sorry.
Jim.
Sorry.
Jim.
It's never nice to receive a grade C, so savalou, I sympathise. However, RayLeong, this is the first time I have actually seen a grade C given appropriately. Thank you for reading (and understanding ;-)) the grading guidelines ;-)
ASKER
Savalou had gave a sugguestion which is quite valid. The problem lies in my question. I don't think my question has an answer, so I really should not mislead the public into thinking that this question is closed with a proper solution. Savalou, no offends for the C grade though.
java.util.Currency may be what you want.
It has two methods to retrieve the currency symbols.