Java currency symbols

From EggeWiki
Revision as of 11:07, 30 August 2010 by Brianegge (talk | contribs) (Created page with '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…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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"));

</geshi>

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