public Money(Locale loc, long val) { this(NumberFormat.getCurrencyInstance(loc).getCurrency(), val); }
private static String getDefaultCurrencyCode() { try { return DEFAULT_CURRENCY_FORMAT.getCurrency().getCurrencyCode(); } catch (UnsupportedOperationException e) { return ""; } }
public Money(Locale loc, double val) { this(NumberFormat.getCurrencyInstance(loc).getCurrency(), val); }
private static String getDefaultCurrencyCode() { try { return DEFAULT_CURRENCY_FORMAT.getCurrency().getCurrencyCode(); } catch (final UnsupportedOperationException e) { return ""; } }
public Money(Locale loc, long whole, int part) { this(NumberFormat.getCurrencyInstance(loc).getCurrency(), whole, part); }
/** * Returns the <tt>Currency</tt> object used to display currency * amounts. This may be null. * @stable ICU 2.6 */ public Currency getCurrency() { return new Currency(numberFormat.getCurrency()); }
public String getCurrencyCode() { if (currencyCode == null) { currencyCode = NumberFormat.getCurrencyInstance(locale).getCurrency().getCurrencyCode(); } return currencyCode; }
@Override public Currency getCurrency() { java.util.Currency jdkCurrency = fJdkNfmt.getCurrency(); if (jdkCurrency == null) { return null; } return Currency.getInstance(jdkCurrency.getCurrencyCode()); }
public String getCurrencySymbol() { if (currencySymbol == null) { currencySymbol = NumberFormat.getCurrencyInstance(locale).getCurrency().getSymbol(); } return currencySymbol; }
/** * Returns the <tt>Currency</tt> object used to display currency * amounts. This may be null. * @stable ICU 2.6 */ public Currency getCurrency() { return new Currency(numberFormat.getCurrency()); }
/** * currency with currency default precision (normally:2). object types must be {@link BigDecimal}! * * @return standard currency regular expression for current locale */ public static final Format getCurrencyFormat() { Currency c = NumberFormat.getCurrencyInstance().getCurrency(); return getCurrencyFormat(c); }
@Override public StringBuffer format(CurrencyAmount currAmt, StringBuffer toAppendTo, FieldPosition pos) { java.util.Currency save = fJdkNfmt.getCurrency(); String currCode = currAmt.getCurrency().getCurrencyCode(); boolean same = save.getCurrencyCode().equals(currCode); if (!same) { fJdkNfmt.setCurrency(java.util.Currency.getInstance(currCode)); } fJdkNfmt.format(currAmt.getNumber(), toAppendTo, pos); if (!same) { fJdkNfmt.setCurrency(save); } return toAppendTo; }
public String getFormattedCurrencyValue(String number){ BigDecimal num = new BigDecimal(number); NumberFormat nf = NumberFormat.getCurrencyInstance(locale); Currency currency = nf.getCurrency(); String str = StringUtil.replace( nf.format(number), nf.getCurrency().getSymbol(locale), "",false).trim(); return currency.getCurrencyCode()+str; }
private static NumberFormat getNumberFormat(String currencyCode) { Currency currency = Currency.getInstance(currencyCode); Locale[] locales = NumberFormat.getAvailableLocales(); for (Locale locale : locales) { NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale); if (numberFormat.getCurrency() == currency) return numberFormat; } return null; }
NumberFormat.getCurrencyInstance().getCurrency().getSymbol()
/** * getCurrencyPostfix * * @return regexp for currency postfix */ protected static final String getCurrencyPostfix() { return getCurrencyPostfix(NumberFormat.getCurrencyInstance().getCurrency().getSymbol()); }
public static String replaceString(double value){ NumberFormat formatter = NumberFormat.getCurrencyInstance(); String currencySymbol = formatter.getCurrency().getSymbol(); String moneyString = formatter.format(value); return moneyString.replace(currencySymbol, ""); } public static String convert(double x){ return replaceString(x); }
/** * getCurrencyPostfix * * @param locale currency locale * @return regexp for currency postfix */ protected static final String getCurrencyPostfix(Locale locale) { return getCurrencyPostfix(NumberFormat.getCurrencyInstance(locale).getCurrency().getSymbol()); }
String userInput = "250.00 SEK"; final Set<Currency> availableCurrencies = Currency.getAvailableCurrencies(); for (Currency availableCurrency : availableCurrencies) { final String strCode = availableCurrency.getCurrencyCode(); final String currencyCode = strCode; if (userInput.contains(currencyCode)){ for (Locale locale : NumberFormat.getAvailableLocales()) { String code = NumberFormat.getCurrencyInstance(locale).getCurrency().getCurrencyCode(); if (strCode.equals(code)) { System.out.println(locale.getDisplayCountry());; } } } }
private static Collection<Locale> getLocalesFromIso4217(String iso4217code) { Collection<Locale> returnValue = new LinkedList<Locale>(); for (Locale locale : NumberFormat.getAvailableLocales()) { String code = NumberFormat.getCurrencyInstance(locale). getCurrency().getCurrencyCode(); if (iso4217code.equals(code)) { returnValue.add(locale); } } return returnValue; } public static void main(String[] args) { System.out.println(getLocalesFromIso4217("USD")); System.out.println(getLocalesFromIso4217("EUR")); for (Locale locale : getLocalesFromIso4217("EUR")) { System.out.println(locale + "=>" + NumberFormat.getCurrencyInstance(locale).format(1234)); } }