Example usage for java.util Currency getSymbol

List of usage examples for java.util Currency getSymbol

Introduction

In this page you can find the example usage for java.util Currency getSymbol.

Prototype

public String getSymbol(Locale locale) 

Source Link

Document

Gets the symbol of this currency for the specified locale.

Usage

From source file:Main.java

public static void main(String args[]) {

    // create a currency for uk locale
    Locale locale = Locale.UK;
    Currency curr = Currency.getInstance(locale);

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

From source file:net.rrm.ehour.ui.admin.config.MainConfigBackingBean.java

public static List<Locale> getAvailableCurrencies() {
    List<Locale> locales = getAvailableLocales();
    SortedSet<Locale> currencyLocales = new TreeSet<>(new Comparator<Locale>() {
        public int compare(Locale o1, Locale o2) {
            Currency curr1 = Currency.getInstance(o1);
            Currency curr2 = Currency.getInstance(o2);

            return (o1.getDisplayCountry() + ": " + curr1.getSymbol(o1))
                    .compareTo(o2.getDisplayCountry() + ": " + curr2.getSymbol(o2));
        }//from   w w w .j a  v  a  2 s. com
    });

    for (Locale locale : locales) {
        if (!StringUtils.isBlank(locale.getCountry())) {
            currencyLocales.add(locale);
        }
    }

    return new ArrayList<>(currencyLocales);
}

From source file:org.libreplan.web.common.ConfigurationModel.java

private static Map<String, String> getAllCurrencies() {
    Map<String, String> currencies = new TreeMap<>();
    for (Locale locale : Locale.getAvailableLocales()) {
        if (StringUtils.isNotBlank(locale.getCountry())) {
            Currency currency = Currency.getInstance(locale);
            currencies.put(currency.getCurrencyCode(), currency.getSymbol(locale));
        }/*  w  w w  .ja  v  a  2  s .c om*/
    }
    return currencies;
}

From source file:com.erudika.para.i18n.CurrencyUtils.java

private CurrencyUtils() {
    Locale[] locales = Locale.getAvailableLocales();
    try {//ww  w .j a  va2  s.c o  m
        for (Locale l : locales) {
            if (!StringUtils.isBlank(l.getCountry())) {
                COUNTRY_TO_LOCALE_MAP.put(l.getCountry(), l);
                Currency c = Currency.getInstance(l);
                if (c != null) {
                    CURRENCY_TO_LOCALE_MAP.put(c.getCurrencyCode(), l);
                    CURRENCIES_MAP.put(c.getCurrencyCode(),
                            getCurrencyName(c.getCurrencyCode(), Locale.US).concat(" ").concat(c.getSymbol(l)));
                }
            }
        }
        // overwrite main locales
        CURRENCY_TO_LOCALE_MAP.put("USD", Locale.US);
        CURRENCY_TO_LOCALE_MAP.put("EUR", Locale.FRANCE);
    } catch (Exception e) {
        logger.error(null, e);
    }
}

From source file:org.gnucash.android.ui.transactions.NewTransactionFragment.java

public void onAccountChanged(long newAccountId) {
    AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(getActivity());
    String currencyCode = accountsDbAdapter.getCurrencyCode(newAccountId);
    Currency currency = Currency.getInstance(currencyCode);
    mCurrencyTextView.setText(currency.getSymbol(Locale.getDefault()));
    accountsDbAdapter.close();/*from   w  w  w.j ava2s  .c o m*/
}

From source file:org.gnucash.android.ui.transactions.NewTransactionFragment.java

/**
 * Initialize views with default data for new transactions
 *//*w w  w  .j av  a  2  s  .c  o  m*/
private void initalizeViews() {
    Date time = new Date(System.currentTimeMillis());
    mDateTextView.setText(DATE_FORMATTER.format(time));
    mTimeTextView.setText(TIME_FORMATTER.format(time));
    mTime = mDate = Calendar.getInstance();

    String typePref = PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getString(getString(R.string.key_default_transaction_type), "DEBIT");
    if (typePref.equals("CREDIT")) {
        mTransactionTypeButton.setChecked(false);
    }

    final long accountId = getArguments().getLong(TransactionsListFragment.SELECTED_ACCOUNT_ID);
    String code = Money.DEFAULT_CURRENCY_CODE;
    if (accountId != 0)
        code = mTransactionsDbAdapter.getCurrencyCode(accountId);

    Currency accountCurrency = Currency.getInstance(code);
    mCurrencyTextView.setText(accountCurrency.getSymbol(Locale.getDefault()));
}

From source file:org.gnucash.android.ui.transaction.TransactionFormFragment.java

/**
 * Callback when the account in the navigation bar is changed by the user
 * @param newAccountId Database record ID of the newly selected account
 *//*www  .ja  va 2s  .  c  o  m*/
public void onAccountChanged(long newAccountId) {
    AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(getActivity());
    String currencyCode = accountsDbAdapter.getCurrencyCode(newAccountId);
    Currency currency = Currency.getInstance(currencyCode);
    mCurrencyTextView.setText(currency.getSymbol(Locale.getDefault()));

    Account.AccountType previousAccountType = mAccountType;
    mAccountType = accountsDbAdapter.getAccountType(newAccountId);
    toggleTransactionTypeState();

    //if the new account has a different credit/debit philosophy as the previous one, then toggle the button
    if (mAccountType.hasDebitNormalBalance() != previousAccountType.hasDebitNormalBalance()) {
        mTransactionTypeButton.toggle();
    }

    updateTransferAccountsList();

    accountsDbAdapter.close();
}

From source file:org.gnucash.android.ui.transaction.TransactionFormFragment.java

/**
* Initialize views with default data for new transactions
*//* w  w w .j  a  va 2s .  c  o m*/
private void initalizeViews() {
    Date time = new Date(System.currentTimeMillis());
    mDateTextView.setText(DATE_FORMATTER.format(time));
    mTimeTextView.setText(TIME_FORMATTER.format(time));
    mTime = mDate = Calendar.getInstance();

    String typePref = PreferenceManager.getDefaultSharedPreferences(getActivity())
            .getString(getString(R.string.key_default_transaction_type), "DEBIT");
    if (typePref.equals("CREDIT")) {
        if (mAccountType.hasDebitNormalBalance())
            mTransactionTypeButton.setChecked(false);
        else
            mTransactionTypeButton.setChecked(true);
    } else { //DEBIT
        if (mAccountType.hasDebitNormalBalance())
            mTransactionTypeButton.setChecked(true);
        else
            mTransactionTypeButton.setChecked(false);
    }

    final long accountId = getArguments().getLong(UxArgument.SELECTED_ACCOUNT_ID);
    String code = Money.DEFAULT_CURRENCY_CODE;
    if (accountId != 0) {
        code = mTransactionsDbAdapter.getCurrencyCode(accountId);
    }
    Currency accountCurrency = Currency.getInstance(code);
    mCurrencyTextView.setText(accountCurrency.getSymbol(Locale.getDefault()));

    if (mUseDoubleEntry) {
        long defaultTransferAccountID = mAccountsDbAdapter.getDefaultTransferAccountID(accountId);
        if (defaultTransferAccountID > 0) {
            setSelectedTransferAccount(defaultTransferAccountID);
        }
    }
}

From source file:org.rythmengine.utils.S.java

/**
 * Format give data into currency using locale info from the engine specified
 * //from   w w w. ja  va 2s . c  o m
 * <p>The method accept any data type. When <code>null</code> is found then 
 * <code>NullPointerException</code> will be thrown out; if an <code>Number</code>
 * is passed in, it will be type cast to <code>Number</code>; otherwise 
 * a <code>Double.valueOf(data.toString())</code> is used to find out
 * the number</p>
 *
 * @param template
 * @param data
 * @param currencyCode
 * @param locale
 * @return the currency
 */
public static String formatCurrency(ITemplate template, Object data, String currencyCode, Locale locale) {
    if (null == data)
        throw new NullPointerException();
    Number number;
    if (data instanceof Number) {
        number = (Number) data;
    } else {
        number = Double.parseDouble(data.toString());
    }
    if (null == locale)
        locale = I18N.locale(template);
    Currency currency = null == currencyCode ? Currency.getInstance(locale)
            : Currency.getInstance(currencyCode);
    NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale);
    numberFormat.setCurrency(currency);
    numberFormat.setMaximumFractionDigits(currency.getDefaultFractionDigits());
    String s = numberFormat.format(number);
    s = s.replace(currency.getCurrencyCode(), currency.getSymbol(locale));
    return s;
}