Java currency symbols

From EggeWiki
Jump to navigation Jump to search

It's possible to get currency symbol codes out of Java, though as of version 1.6 it's a bit painful.

<geshi lang="java5">

   public static final String EURO_SYMBOL = Currency.getInstance("EUR").getSymbol(new Locale("el", "GR"));
   public static final String STERLING_POUND_SYMBOL = Currency.getInstance("GBP").getSymbol(new Locale("en", "GB"));
   public static final String US_DOLLAR_SYMBOL = Currency.getInstance("USD").getSymbol(new Locale("en", "US"));


The pain comes from the fact that common currency codes are only defined in the country in which they are used. This means if you use the default locale, you'll probably see the ISO 4217 value, not the symbol code.

See also