/** * Sets the <tt>Currency</tt> object used to display currency amounts. This takes * effect immediately, if this format is a currency format. If this format is not a * currency format, then the currency object is used if and when this object becomes a * currency format through the application of a new pattern. * * @param theCurrency new currency object to use. Must not be null. * @stable ICU 2.2 */ public void setCurrency(Currency theCurrency) { super.setCurrency(theCurrency); }
/** * Sets the <tt>Currency</tt> object used to display currency amounts. This takes * effect immediately, if this format is a currency format. If this format is not a * currency format, then the currency object is used if and when this object becomes a * currency format through the application of a new pattern. * * @param theCurrency new currency object to use. Must not be null. * @stable ICU 2.2 */ public void setCurrency(Currency theCurrency) { super.setCurrency(theCurrency); }
@Override public void setCurrency(Currency currency) { if (currency == null) { fIcuNfmt.setCurrency(null); } else { fIcuNfmt.setCurrency(com.ibm.icu.util.Currency.getInstance(currency.getCurrencyCode())); } }
/** * Override Format.format(). * @see java.text.Format#format(java.lang.Object, java.lang.StringBuffer, java.text.FieldPosition) */ public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) { if (!(obj instanceof CurrencyAmount)) { throw new IllegalArgumentException("Invalid type: " + obj.getClass().getName()); } CurrencyAmount currency = (CurrencyAmount) obj; fmt.setCurrency(currency.getCurrency()); return fmt.format(currency.getNumber(), toAppendTo, pos); }
/** * {@icu} Formats a CurrencyAmount. Specialization of format. * @see java.text.Format#format(Object, StringBuffer, FieldPosition) * @stable ICU 3.0 */ public StringBuffer format(CurrencyAmount currAmt, StringBuffer toAppendTo, FieldPosition pos) { // Default implementation -- subclasses may override synchronized(this) { Currency save = getCurrency(), curr = currAmt.getCurrency(); boolean same = curr.equals(save); if (!same) setCurrency(curr); format(currAmt.getNumber(), toAppendTo, pos); if (!same) setCurrency(save); } return toAppendTo; }
NumberFormat createInstance(ULocale desiredLocale, int choice) { // use service cache // if (service.isDefault()) { // return NumberFormat.createInstance(desiredLocale, choice); // } ULocale[] actualLoc = new ULocale[1]; NumberFormat fmt = (NumberFormat)service.get(desiredLocale, choice, actualLoc); if (fmt == null) { throw new MissingResourceException("Unable to construct NumberFormat", "", ""); } fmt = (NumberFormat)fmt.clone(); // If we are creating a currency type formatter, then we may have to set the currency // explicitly, since the actualLoc may be different than the desiredLocale if ( choice == NumberFormat.CURRENCYSTYLE || choice == NumberFormat.ISOCURRENCYSTYLE || choice == NumberFormat.PLURALCURRENCYSTYLE) { fmt.setCurrency(Currency.getInstance(desiredLocale)); } ULocale uloc = actualLoc[0]; fmt.setLocale(uloc, uloc); // services make no distinction between actual & valid return fmt; }
@Override public Number parseCurrencyAmount(String locale, String value, String currencyCode) throws ParseException { ULocale closestLocale = localeService.getClosestULocale(locale); Currency currency; if (StringUtils.isEmpty(currencyCode)) { currency = Currency.getInstance(new ULocale(locale)); } else { currency = Currency.getInstance(currencyCode); } NumberFormat nf = NumberFormat.getCurrencyInstance(closestLocale); nf.setCurrency(currency); return nf.parse(value); }
@Override public Number parseCurrencyAmount(String locale, String value, String currencyCode) throws ParseException { ULocale closestLocale = findClosestULocale(locale); Currency currency; if (StringUtils.isEmpty(currencyCode)) { currency = Currency.getInstance(new ULocale(locale)); } else { currency = Currency.getInstance(currencyCode); } NumberFormat nf = NumberFormat.getCurrencyInstance(closestLocale); nf.setCurrency(currency); return nf.parse(value); }
@Override public String formatCurrencyAmount(String locale, Number amount, String currencyCode) { ULocale closestLocale = findClosestULocale(locale); Currency currency; if (StringUtils.isEmpty(currencyCode)) { currency = Currency.getInstance(new ULocale(locale)); } else { currency = Currency.getInstance(currencyCode); } CurrencyAmount ca = new CurrencyAmount(amount, currency); NumberFormat nf = NumberFormat.getCurrencyInstance(closestLocale); nf.setCurrency(currency); return nf.format(ca); }
@Override public String formatCurrencyAmount(String locale, Number amount, String currencyCode) { ULocale closestLocale = localeService.getClosestULocale(locale); Currency currency; if (StringUtils.isEmpty(currencyCode)) { currency = Currency.getInstance(new ULocale(locale)); } else { currency = Currency.getInstance(currencyCode); } CurrencyAmount ca = new CurrencyAmount(amount, currency); NumberFormat nf = NumberFormat.getCurrencyInstance(closestLocale); nf.setCurrency(currency); return nf.format(ca); }
/** Formats a double into a properly formatted currency string based on isoCode and Locale * @param price The price double to be formatted * @param isoCode the currency ISO code * @param locale The Locale used to format the number * @param maximumFractionDigits The maximum number of fraction digits used; if set to -1 than the default value for the locale is used * @return A String with the formatted price */ public static String formatCurrency(double price, String isoCode, Locale locale, int maximumFractionDigits) { com.ibm.icu.text.NumberFormat nf = com.ibm.icu.text.NumberFormat.getCurrencyInstance(locale); if (isoCode != null && isoCode.length() > 1) { nf.setCurrency(com.ibm.icu.util.Currency.getInstance(isoCode)); } else { if (Debug.verboseOn()) { Debug.logVerbose("No isoCode specified to format currency value:" + price, module); } } if (maximumFractionDigits >= 0) { nf.setMaximumFractionDigits(maximumFractionDigits); } return nf.format(price); }
case NF_CURRENCY: result = NumberFormat.getCurrencyInstance(nfLocale); result.setCurrency(getCurrency()); break; default:
super.setCurrency(theCurrency); if (theCurrency != null) { String s = theCurrency.getName(symbols.getULocale(), Currency.SYMBOL_NAME, null);