List of usage examples for java.util Currency getDefaultFractionDigits
public int getDefaultFractionDigits()
From source file:ro.expectations.expenses.ui.transactions.TransactionsAdapter.java
private void processCredit(ViewHolder holder, int position) { mCursor.moveToPosition(position);/*from w w w.j av a2s .c o m*/ // Set the account String toAccount = mCursor.getString(TransactionsFragment.COLUMN_TO_ACCOUNT_TITLE); holder.mAccount.setText(toAccount); // Set the amount double toAmount = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_TO_AMOUNT) / 100.0); NumberFormat format = NumberFormat.getCurrencyInstance(); String toCurrencyCode = mCursor.getString(TransactionsFragment.COLUMN_TO_CURRENCY); Currency toCurrency = Currency.getInstance(toCurrencyCode); format.setCurrency(toCurrency); format.setMaximumFractionDigits(toCurrency.getDefaultFractionDigits()); holder.mAmount.setText(format.format(toAmount)); holder.mAmount.setTextColor(ContextCompat.getColor(mContext, R.color.colorGreen700)); double toBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_TO_BALANCE) / 100.0); holder.mRunningBalance.setText(format.format(toBalance)); // Set the transaction type icon holder.mTypeIcon.setImageDrawable( DrawableHelper.tint(mContext, R.drawable.ic_call_received_black_24dp, R.color.colorGreen700)); }
From source file:ro.expectations.expenses.ui.transactions.TransactionsAdapter.java
private void processDebit(ViewHolder holder, int position) { mCursor.moveToPosition(position);//from w w w. j a va 2s. c o m // Set the account String fromAccount = mCursor.getString(TransactionsFragment.COLUMN_FROM_ACCOUNT_TITLE); holder.mAccount.setText(fromAccount); // Set the amount double fromAmount = NumberUtils .roundToTwoPlaces(0 - mCursor.getLong(TransactionsFragment.COLUMN_FROM_AMOUNT) / 100.0); NumberFormat format = NumberFormat.getCurrencyInstance(); String fromCurrencyCode = mCursor.getString(TransactionsFragment.COLUMN_FROM_CURRENCY); Currency fromCurrency = Currency.getInstance(fromCurrencyCode); format.setCurrency(fromCurrency); format.setMaximumFractionDigits(fromCurrency.getDefaultFractionDigits()); holder.mAmount.setText(format.format(fromAmount)); holder.mAmount.setTextColor(ContextCompat.getColor(mContext, R.color.colorRed700)); double fromBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_BALANCE) / 100.0); holder.mRunningBalance.setText(format.format(fromBalance)); // Set the transaction type icon holder.mTypeIcon.setImageDrawable( DrawableHelper.tint(mContext, R.drawable.ic_call_made_black_24dp, R.color.colorRed700)); }
From source file:ro.expectations.expenses.ui.transactions.TransactionsAdapter.java
private void processTransfer(ViewHolder holder, int position) { mCursor.moveToPosition(position);/*ww w.j av a 2 s. c o m*/ // Set the account String fromAccount = mCursor.getString(TransactionsFragment.COLUMN_FROM_ACCOUNT_TITLE); String toAccount = mCursor.getString(TransactionsFragment.COLUMN_TO_ACCOUNT_TITLE); holder.mAccount.setText(mContext.getResources().getString(R.string.breadcrumbs, fromAccount, toAccount)); // Set the amount NumberFormat format = NumberFormat.getCurrencyInstance(); String fromCurrencyCode = mCursor.getString(TransactionsFragment.COLUMN_FROM_CURRENCY); String toCurrencyCode = mCursor.getString(TransactionsFragment.COLUMN_TO_CURRENCY); if (fromCurrencyCode.equals(toCurrencyCode)) { double amount = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_AMOUNT) / 100.0); Currency currency = Currency.getInstance(fromCurrencyCode); format.setCurrency(currency); format.setMaximumFractionDigits(currency.getDefaultFractionDigits()); holder.mAmount.setText(format.format(amount)); double fromBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_BALANCE) / 100.0); String fromBalanceFormatted = format.format(fromBalance); double toBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_TO_BALANCE) / 100.0); holder.mRunningBalance.setText(mContext.getResources().getString(R.string.breadcrumbs, fromBalanceFormatted, format.format(toBalance))); } else { Currency fromCurrency = Currency.getInstance(fromCurrencyCode); format.setCurrency(fromCurrency); format.setMaximumFractionDigits(fromCurrency.getDefaultFractionDigits()); double fromAmount = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_AMOUNT) / 100.0); String fromAmountFormatted = format.format(fromAmount); double fromBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_BALANCE) / 100.0); String fromBalanceFormatted = format.format(fromBalance); Currency toCurrency = Currency.getInstance(toCurrencyCode); format.setCurrency(toCurrency); format.setMaximumFractionDigits(toCurrency.getDefaultFractionDigits()); double toAmount = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_TO_AMOUNT) / 100.0); double toBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_TO_BALANCE) / 100.0); holder.mAmount.setText(mContext.getResources().getString(R.string.breadcrumbs, fromAmountFormatted, format.format(toAmount))); holder.mRunningBalance.setText(mContext.getResources().getString(R.string.breadcrumbs, fromBalanceFormatted, format.format(toBalance))); } // Set the color for the amount and the transaction type icon if (mSelectedAccountId == 0) { holder.mAmount.setTextColor(ContextCompat.getColor(mContext, R.color.colorOrange700)); holder.mTypeIcon.setImageDrawable( DrawableHelper.tint(mContext, R.drawable.ic_swap_horiz_black_24dp, R.color.colorOrange700)); } else { long fromAccountId = mCursor.getLong(TransactionsFragment.COLUMN_FROM_ACCOUNT_ID); long toAccountId = mCursor.getLong(TransactionsFragment.COLUMN_TO_ACCOUNT_ID); if (mSelectedAccountId == fromAccountId) { holder.mAmount.setTextColor(ContextCompat.getColor(mContext, R.color.colorRed700)); holder.mTypeIcon.setImageDrawable( DrawableHelper.tint(mContext, R.drawable.ic_call_made_black_24dp, R.color.colorRed700)); } else if (mSelectedAccountId == toAccountId) { holder.mAmount.setTextColor(ContextCompat.getColor(mContext, R.color.colorGreen700)); holder.mTypeIcon.setImageDrawable(DrawableHelper.tint(mContext, R.drawable.ic_call_received_black_24dp, R.color.colorGreen700)); } } }
From source file:org.moqui.impl.context.L10nFacadeImpl.java
@Override public String formatCurrency(Object amount, String uomId, Integer fractionDigits, Locale locale) { if (amount == null) return ""; if (amount instanceof CharSequence) { if (((CharSequence) amount).length() == 0) { return ""; } else {/*from w w w. j a v a 2 s.c om*/ amount = parseNumber((String) amount, null); } } if (locale == null) locale = getLocale(); NumberFormat nf = NumberFormat.getCurrencyInstance(locale); Currency currency = uomId != null && uomId.length() > 0 ? Currency.getInstance(uomId) : null; if (currency != null) nf.setCurrency(currency); if (fractionDigits == null) fractionDigits = currency != null ? currency.getDefaultFractionDigits() : 2; nf.setMaximumFractionDigits(fractionDigits); nf.setMinimumFractionDigits(fractionDigits); return nf.format(amount); }
From source file:com.aoindustries.creditcards.TransactionRequest.java
/** * Sets the currency code for this transaction. The currency should be set * before the monetary amounts in order to properly scale the amounts. If * the currency is reset, the amounts will be scaled. This may result * in an ArithmentException./*w w w . j a va 2s . c om*/ */ public void setCurrency(Currency currency) { this.currency = currency; int scale = currency.getDefaultFractionDigits(); if (amount != null) amount = amount.setScale(scale); if (taxAmount != null) taxAmount = taxAmount.setScale(scale); if (shippingAmount != null) shippingAmount = shippingAmount.setScale(scale); if (dutyAmount != null) dutyAmount = dutyAmount.setScale(scale); }
From source file:org.totschnig.myexpenses.util.Utils.java
/** * @param currency/*from w w w . j av a 2s.c o m*/ * @param separator * @return a Decimalformat with the number of fraction digits appropriate for * currency, and with the given separator, but without the currency * symbol appropriate for CSV and QIF export */ public static DecimalFormat getDecimalFormat(Currency currency, char separator) { DecimalFormat nf = new DecimalFormat(); DecimalFormatSymbols symbols = new DecimalFormatSymbols(); symbols.setDecimalSeparator(separator); nf.setDecimalFormatSymbols(symbols); int fractionDigits = currency.getDefaultFractionDigits(); if (fractionDigits != -1) { nf.setMinimumFractionDigits(fractionDigits); nf.setMaximumFractionDigits(fractionDigits); } else { nf.setMaximumFractionDigits(Money.DEFAULTFRACTIONDIGITS); } nf.setGroupingUsed(false); return nf; }
From source file:de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderTest.java
/** * This is test for issue #34:// w w w.j av a 2 s . c om * msm-javolution-serializer: java.util.Currency gets deserialized with ReflectionFormat * * See http://code.google.com/p/memcached-session-manager/issues/detail?id=34 * * @throws Exception */ @Test(enabled = true) public void testCurrency() throws Exception { final MemcachedBackupSession session = _manager.createEmptySession(); session.setValid(true); final Currency orig = Currency.getInstance("EUR"); session.setAttribute("currency1", orig); session.setAttribute("currency2", orig); final Map<String, Object> deserialized = _transcoder .deserializeAttributes(_transcoder.serializeAttributes(session, session.getAttributesInternal())); assertDeepEquals(deserialized, session.getAttributesInternal()); // Check that the transient field defaultFractionDigits is initialized correctly (that was the bug) final Currency currency1 = (Currency) deserialized.get("currency1"); Assert.assertEquals(currency1.getCurrencyCode(), orig.getCurrencyCode()); Assert.assertEquals(currency1.getDefaultFractionDigits(), orig.getDefaultFractionDigits()); }
From source file:de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderTest.java
private void assertDeepEquals(final Object one, final Object another, final Map<Object, Object> alreadyChecked) throws Exception { if (one == another) { return;/*from w w w . j a v a 2 s . c o m*/ } if (one == null && another != null || one != null && another == null) { Assert.fail("One of both is null: " + one + ", " + another); } if (alreadyChecked.containsKey(one)) { return; } alreadyChecked.put(one, another); Assert.assertEquals(one.getClass(), another.getClass()); if (one.getClass().isPrimitive() || one instanceof String || one instanceof Character || one instanceof Boolean) { Assert.assertEquals(one, another); return; } if (Map.class.isAssignableFrom(one.getClass())) { final Map<?, ?> m1 = (Map<?, ?>) one; final Map<?, ?> m2 = (Map<?, ?>) another; Assert.assertEquals(m1.size(), m2.size()); for (final Map.Entry<?, ?> entry : m1.entrySet()) { assertDeepEquals(entry.getValue(), m2.get(entry.getKey())); } return; } if (Number.class.isAssignableFrom(one.getClass())) { Assert.assertEquals(((Number) one).longValue(), ((Number) another).longValue()); return; } if (one instanceof Currency) { // Check that the transient field defaultFractionDigits is initialized correctly (that was issue #34) final Currency currency1 = (Currency) one; final Currency currency2 = (Currency) another; Assert.assertEquals(currency1.getCurrencyCode(), currency2.getCurrencyCode()); Assert.assertEquals(currency1.getDefaultFractionDigits(), currency2.getDefaultFractionDigits()); } Class<? extends Object> clazz = one.getClass(); while (clazz != null) { assertEqualDeclaredFields(clazz, one, another, alreadyChecked); clazz = clazz.getSuperclass(); } }
From source file:org.rythmengine.utils.S.java
/** * Format give data into currency using locale info from the engine specified * /*from ww w . j av a2s.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; }
From source file:de.javakaffee.kryoserializers.KryoTest.java
@Test(enabled = true) public void testCurrency() throws Exception { final Currency currency = Currency.getInstance("EUR"); final Currency deserialized = deserialize(serialize(currency), Currency.class); assertDeepEquals(deserialized, currency); // Check that the transient field defaultFractionDigits is initialized correctly Assert.assertEquals(deserialized.getCurrencyCode(), currency.getCurrencyCode()); Assert.assertEquals(deserialized.getDefaultFractionDigits(), currency.getDefaultFractionDigits()); }