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() 

Source Link

Document

Gets the symbol of this currency for the default Locale.Category#DISPLAY DISPLAY locale.

Usage

From source file:org.yawlfoundation.yawl.util.StringUtil.java

/**
 * Utility routine which takes a decimal value as a string (e.g. 0.25 equating to 25p) and returns the
 * value in UI currency format (e.g. 0.25).
 *
 * @return A formatted currency/*w  ww  . java 2 s  .  com*/
 */
public static String formatDecimalCost(BigDecimal value) {
    Currency currency = Currency.getInstance(Locale.getDefault());
    NumberFormat fmt = DecimalFormat.getInstance();
    fmt.setMinimumFractionDigits(2);
    fmt.setMaximumFractionDigits(2);
    return currency.getSymbol() + fmt.format(value);
}

From source file:com.pamarin.income.controller.NormalSettingsCtrl.java

private void sortBySymbolAscending() {
    Collections.sort(currencys, new Comparator<Currency>() {

        @Override/*from   ww w  . j av  a2  s. com*/
        public int compare(Currency o1, Currency o2) {
            return o1.getSymbol().compareTo(o2.getSymbol());
        }
    });
}

From source file:org.orcid.core.cli.MigrateFundingAmountToANumericValue.java

private BigDecimal getAmountAsBigDecimal(String amount, String currencyCode, Locale locale) throws Exception {
    try {/*from w  w  w  .j  a v  a2  s.c o m*/
        ParsePosition parsePosition = new ParsePosition(0);
        NumberFormat numberFormat = NumberFormat.getInstance(locale);
        Number number = null;
        if (!PojoUtil.isEmpty(currencyCode)) {
            Currency currency = Currency.getInstance(currencyCode);
            String currencySymbol = currency.getSymbol();
            number = numberFormat.parse(amount.replace(currencySymbol, StringUtils.EMPTY), parsePosition);
        } else {
            number = numberFormat.parse(amount, parsePosition);
        }
        if (parsePosition.getIndex() != amount.length())
            throw new Exception("Unable to parse amount into BigDecimal");
        return new BigDecimal(number.toString());
    } catch (Exception e) {
        throw e;
    }
}

From source file:org.apache.empire.struts2.jsp.controls.TextInputControl.java

private String getUnitString(ValueInfo vi) {
    // Is unit supplied as a format option
    String format = getFormatOption(vi, FORMAT_UNIT);
    if (format != null)
        return format;
    // Is it a currency column
    Column column = vi.getColumn();//w w w  .j a  v a  2s  . co  m
    if (column != null && column.getDataType() == DataType.DECIMAL) {
        String numberType = StringUtils.toString(column.getAttribute(InputControl.NUMBER_FORMAT_ATTRIBUTE));
        if (numberType != null) {
            if (numberType.equalsIgnoreCase("Currency")) {
                String currencyCode = StringUtils
                        .toString(column.getAttribute(InputControl.CURRENCY_CODE_ATTRIBUTE));
                if (currencyCode != null) { // nf = NumberFormat.getCurrencyInstance(locale);
                    Currency currency = Currency.getInstance(currencyCode);
                    return (currency != null) ? currency.getSymbol() : null;
                }
            } else if (numberType.equalsIgnoreCase("Percent")) {
                return "%";
            }
        }
    }
    // No Unit supplied
    return null;
}

From source file:org.gnucash.android.ui.transaction.dialog.SplitEditorDialogFragment.java

/**
 * Binds the different UI elements of an inflated list view to corresponding actions
 * @param splitView Split item view//www . j  a v a 2 s .  com
 * @param split {@link org.gnucash.android.model.Split} to use to populate the view
 */
private void bindSplitView(final View splitView, Split split) {
    EditText splitMemoEditText = (EditText) splitView.findViewById(R.id.input_split_memo);
    final EditText splitAmountEditText = (EditText) splitView.findViewById(R.id.input_split_amount);
    ImageButton removeSplitButton = (ImageButton) splitView.findViewById(R.id.btn_remove_split);
    Spinner accountsSpinner = (Spinner) splitView.findViewById(R.id.input_accounts_spinner);
    final TextView splitCurrencyTextView = (TextView) splitView.findViewById(R.id.split_currency_symbol);
    final TextView splitUidTextView = (TextView) splitView.findViewById(R.id.split_uid);
    final TransactionTypeToggleButton splitTypeButton = (TransactionTypeToggleButton) splitView
            .findViewById(R.id.btn_split_type);

    splitAmountEditText.addTextChangedListener(new AmountInputFormatter(splitAmountEditText));

    removeSplitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mRemovedSplitUIDs.add(splitUidTextView.getText().toString());
            mSplitsLinearLayout.removeView(splitView);
            mSplitItemViewList.remove(splitView);
            updateTotal();
        }
    });

    updateTransferAccountsList(accountsSpinner);
    accountsSpinner.setOnItemSelectedListener(new TypeButtonLabelUpdater(splitTypeButton));

    Currency accountCurrency = Currency.getInstance(mAccountsDbAdapter.getCurrencyCode(mAccountUID));
    splitCurrencyTextView.setText(accountCurrency.getSymbol());
    splitTypeButton.setAmountFormattingListener(splitAmountEditText, splitCurrencyTextView);
    splitTypeButton.setChecked(mBaseAmount.signum() > 0);
    splitUidTextView.setText(UUID.randomUUID().toString());

    if (split != null) {
        splitAmountEditText.setText(split.getAmount().toPlainString());
        splitMemoEditText.setText(split.getMemo());
        splitUidTextView.setText(split.getUID());
        String splitAccountUID = split.getAccountUID();
        setSelectedTransferAccount(mAccountsDbAdapter.getAccountID(splitAccountUID), accountsSpinner);
        splitTypeButton.setAccountType(mAccountsDbAdapter.getAccountType(splitAccountUID));
        splitTypeButton.setChecked(split.getType());
    }

    //put these balance update triggers last last so as to avoid computing while still loading
    splitAmountEditText.addTextChangedListener(mBalanceUpdater);
    splitTypeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            updateTotal();
        }
    });
}

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

/**
 * Initialize views in the fragment with information from a transaction.
 * This method is called if the fragment is used for editing a transaction
 *///from   ww w  .  ja v a  2s  .  co  m
private void initializeViewsWithTransaction() {

    mNameEditText.setText(mTransaction.getName());
    mTransactionTypeButton.setChecked(mTransaction.getTransactionType() == TransactionType.DEBIT);
    mAmountEditText.setText(mTransaction.getAmount().toPlainString());
    mCurrencyTextView.setText(mTransaction.getAmount().getCurrency().getSymbol(Locale.getDefault()));
    mDescriptionEditText.setText(mTransaction.getDescription());
    mDateTextView.setText(DATE_FORMATTER.format(mTransaction.getTimeMillis()));
    mTimeTextView.setText(TIME_FORMATTER.format(mTransaction.getTimeMillis()));
    Calendar cal = GregorianCalendar.getInstance();
    cal.setTimeInMillis(mTransaction.getTimeMillis());
    mDate = mTime = cal;

    final long accountId = mTransactionsDbAdapter.getAccountID(mTransaction.getAccountUID());
    String code = mTransactionsDbAdapter.getCurrencyCode(accountId);
    Currency accountCurrency = Currency.getInstance(code);
    mCurrencyTextView.setText(accountCurrency.getSymbol());
}

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

/**
* Initialize views in the fragment with information from a transaction.
* This method is called if the fragment is used for editing a transaction
*///w  ww  . j a  v a 2  s.c  om
private void initializeViewsWithTransaction() {
    mNameEditText.setText(mTransaction.getName());

    //FIXME: You need to revisit me when splits are introduced
    //checking the type button means the amount will be shown as negative (in red) to user

    mTransactionTypeButton.setChecked(mTransaction.getAmount().isNegative());

    if (!mAmountManuallyEdited) {
        //when autocompleting, only change the amount if the user has not manually changed it already
        mAmountEditText.setText(mTransaction.getAmount().toPlainString());
    }
    mCurrencyTextView.setText(mTransaction.getAmount().getCurrency().getSymbol(Locale.getDefault()));
    mDescriptionEditText.setText(mTransaction.getDescription());
    mDateTextView.setText(DATE_FORMATTER.format(mTransaction.getTimeMillis()));
    mTimeTextView.setText(TIME_FORMATTER.format(mTransaction.getTimeMillis()));
    Calendar cal = GregorianCalendar.getInstance();
    cal.setTimeInMillis(mTransaction.getTimeMillis());
    mDate = mTime = cal;

    if (mUseDoubleEntry) {
        if (isInDoubleAccount()) {
            long accountId = mTransactionsDbAdapter.getAccountID(mTransaction.getAccountUID());
            setSelectedTransferAccount(accountId);
        } else {
            long doubleAccountId = mTransactionsDbAdapter.getAccountID(mTransaction.getDoubleEntryAccountUID());
            setSelectedTransferAccount(doubleAccountId);
        }
    }

    final long accountId = mTransactionsDbAdapter.getAccountID(mTransaction.getAccountUID());
    String code = mTransactionsDbAdapter.getCurrencyCode(accountId);
    Currency accountCurrency = Currency.getInstance(code);
    mCurrencyTextView.setText(accountCurrency.getSymbol());

    setSelectedRecurrenceOption();
}

From source file:org.totschnig.myexpenses.activity.ExpenseEdit.java

private void configureTransferInput() {
    final Account transferAccount = Account.getInstanceFromDb(mTransferAccountSpinner.getSelectedItemId());
    final Currency currency = getCurrentAccount().currency;
    final boolean isSame = currency.equals(transferAccount.currency);
    findViewById(R.id.TransferAmountRow).setVisibility(isSame ? View.GONE : View.VISIBLE);
    findViewById(R.id.ExchangeRateRow)/*from w  w  w .  ja  va  2  s .c om*/
            .setVisibility(isSame || (mTransaction instanceof Template) ? View.GONE : View.VISIBLE);
    final String symbol2 = transferAccount.currency.getSymbol();
    //noinspection SetTextI18n
    addCurrencyToLabel((TextView) findViewById(R.id.TransferAmountLabel), symbol2);
    mTransferAmountText.setFractionDigits(Money.getFractionDigits(transferAccount.currency));
    final String symbol1 = currency.getSymbol();
    ((TextView) findViewById(R.id.ExchangeRateLabel_1_1)).setText(String.format("1 %s =", symbol1));
    ((TextView) findViewById(R.id.ExchangeRateLabel_1_2)).setText(symbol2);
    ((TextView) findViewById(R.id.ExchangeRateLabel_2_1)).setText(String.format("1 %s =", symbol2));
    ((TextView) findViewById(R.id.ExchangeRateLabel_2_2)).setText(symbol1);

    Bundle bundle = new Bundle(2);
    bundle.putStringArray(KEY_CURRENCY,
            new String[] { currency.getCurrencyCode(), transferAccount.currency.getCurrencyCode() });
    if (!isSame && !mSavedInstance && (mNewInstance || mPlanInstanceId == -1)
            && !(mTransaction instanceof Template)) {
        mManager.restartLoader(LAST_EXCHANGE_CURSOR, bundle, this);
    }
}