20

Currency.getSymbol will give me the major symbol (e.g. "$" for USD) but I'd like to get the minor unit (e.g. "p" for GBP or the cents symbol for USD), without writing my own look up table.

Is there a standard, i.e. built in way to do this?

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
alex.collins
  • 581
  • 4
  • 12
  • 5
    +1 I suspect not. BTW, Not all currencies have a minor symbol. There are three cent characters ¢, ¢ and ₡ – Peter Lawrey Nov 12 '12 at 10:23
  • 1
    +1 You can use [List of countries, territories and currencies](http://publications.europa.eu/code/en/en-5000500.htm) to implement the lookup map. – dan Nov 12 '12 at 10:37
  • Personally I'd look at [the ICU project](http://site.icu-project.org/) or [Joda-Money](http://joda-money.sourceforge.net/) for this kind of data, but both seem to lack this specific piece of information. – Joachim Sauer Nov 12 '12 at 11:40

1 Answers1

-1

I would like to suggest for this situation to use custom custom currency format. Use DecimalFormat or NumberFormat of java.text.* package. There are a lot of example for that.

Example

public class CurrencyFormatExample {
    public void currencyFormat(Locale currentLocale) {
        Double currency = new Double(9843.21);
        NumberFormat currencyFormatter;
        String currencyOut;
        currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);
        currencyOut = currencyFormatter.format(currency);
        System.out.println(currencyOut + " " + currentLocale.toString());
    }

    public static void main(String args[]) {
        Locale[] locales = new Locale[]{new Locale("fr", "FR"),
            new Locale("de", "DE"), new Locale("ca", "CA"),
            new Locale("rs", "RS"),new Locale("en", "IN")
        };
        CurrencyFormatExample[] formate = new CurrencyFormatExample[locales.length];
        for (int i = 0; i < locales.length; i++) {
            formate[i].currencyFormat(locales[i]);
        }
    }
}

Out put:

9Â 843,21 â?¬ fr_FR

9.843,21 â?¬ de_DE

CAD 9.843,21 ca_CA

RSD 9,843.21 rs_RS

Rs.9,843.21 en_IN

Reference here:

Update for minor currency

  Locale locale = Locale.UK;
  Currency curr = Currency.getInstance(locale);

  // get and print the symbol of the currency
  String symbol = curr.getSymbol(locale);
  System.out.println("Symbol is = " + symbol);

Output :

Symbol is = £
Zaw Than oo
  • 9,651
  • 13
  • 83
  • 131
  • How does this answer the submitter's question? As far as I can see, this code outputs the major currency symbol for each locale, not the minor currency. – Richard Neish Jan 06 '14 at 13:58
  • 2
    Sorry, but I think the submitter is asking for a symbol or code for the sub-unit (such as '¢' for USD or 'p' for GBP). See answer http://stackoverflow.com/questions/5023754/do-minor-currency-units-have-a-iso-standard for details. According to that answer, there is no international standard for these. – Richard Neish Jan 06 '14 at 15:53