Search in sources :

Example 26 with Currency

use of java.util.Currency in project lucene-solr by apache.

the class AbstractCurrencyFieldTest method assumeCurrencySupport.

/**
   * "Assumes" that the specified list of currency codes are
   * supported in this JVM
   */
public static void assumeCurrencySupport(String... codes) {
    try {
        // these are the ones needed for this test to work.
        for (String code : codes) {
            Currency obj = Currency.getInstance(code);
            assertNotNull(code, obj);
        }
    } catch (IllegalArgumentException e) {
        Assume.assumeNoException(e);
    }
}
Also used : Currency(java.util.Currency)

Example 27 with Currency

use of java.util.Currency in project jgnash by ccavanaugh.

the class DefaultCurrencies method buildNode.

/**
     * Creates a valid CurrencyNode given a locale.
     *
     * @param locale Locale to create a CurrencyNode for
     * @return The new CurrencyNode
     */
public static CurrencyNode buildNode(final Locale locale) {
    DecimalFormatSymbols symbols = new DecimalFormatSymbols(locale);
    Currency c = symbols.getCurrency();
    CurrencyNode node = new CurrencyNode();
    node.setSymbol(c.getCurrencyCode());
    node.setPrefix(symbols.getCurrencySymbol());
    node.setScale((byte) c.getDefaultFractionDigits());
    return node;
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) Currency(java.util.Currency)

Example 28 with Currency

use of java.util.Currency in project jgnash by ccavanaugh.

the class DefaultCurrencies method buildCustomNode.

/**
     * Creates a custom CurrencyNode given an ISO code.  If the ISO code is
     * not valid, then a node will be generated using the supplied code.  The
     * locale is assumed to be the default locale.
     *
     * @param ISOCode The custom currency to generate
     * @return The custom CurrencyNode
     */
public static CurrencyNode buildCustomNode(final String ISOCode) {
    final CurrencyNode node = new CurrencyNode();
    Currency c;
    try {
        c = Currency.getInstance(ISOCode);
        node.setSymbol(c.getCurrencyCode());
    } catch (Exception e) {
        node.setSymbol(ISOCode);
        Logger.getLogger(DefaultCurrencies.class.getName()).log(Level.FINE, null, e);
    } finally {
        node.setDescription(Locale.getDefault().toString());
    }
    return node;
}
Also used : Currency(java.util.Currency)

Example 29 with Currency

use of java.util.Currency in project jdk8u_jdk by JetBrains.

the class NumberFormatProviderImpl method adjustForCurrencyDefaultFractionDigits.

/**
     * Adjusts the minimum and maximum fraction digits to values that
     * are reasonable for the currency's default fraction digits.
     */
private static void adjustForCurrencyDefaultFractionDigits(DecimalFormat format, DecimalFormatSymbols symbols) {
    Currency currency = symbols.getCurrency();
    if (currency == null) {
        try {
            currency = Currency.getInstance(symbols.getInternationalCurrencySymbol());
        } catch (IllegalArgumentException e) {
        }
    }
    if (currency != null) {
        int digits = currency.getDefaultFractionDigits();
        if (digits != -1) {
            int oldMinDigits = format.getMinimumFractionDigits();
            // Try to adjust all of them in a reasonable way.
            if (oldMinDigits == format.getMaximumFractionDigits()) {
                format.setMinimumFractionDigits(digits);
                format.setMaximumFractionDigits(digits);
            } else {
                format.setMinimumFractionDigits(Math.min(digits, oldMinDigits));
                format.setMaximumFractionDigits(digits);
            }
        }
    }
}
Also used : Currency(java.util.Currency)

Example 30 with Currency

use of java.util.Currency in project Lucee by lucee.

the class LSParseCurrency method toDoubleValue.

public static double toDoubleValue(Locale locale, String str, boolean strict) throws PageException {
    str = str.trim();
    NumberFormat cnf = getCurrencyInstance(locale);
    Currency currency = cnf.getCurrency();
    if (currency.getCurrencyCode().equals("XXX"))
        throw new ExpressionException("Unknown currency [" + locale.toString() + "]");
    cnf.setParseIntegerOnly(false);
    try {
        return cnf.parse(str).doubleValue();
    } catch (ParseException e) {
        String stripped = str.replace(currency.getSymbol(locale), "").replace(currency.getCurrencyCode(), "");
        NumberFormat nf = getInstance(locale);
        ParsePosition pp = new ParsePosition(0);
        Number n = nf.parse(stripped, pp);
        if (n == null || pp.getIndex() == 0 || (strict && stripped.length() != pp.getIndex()))
            throw new ExpressionException(String.format("Unparseable value [%s] for currency %s", str, locale.toString()));
        return n.doubleValue();
    }
}
Also used : Currency(java.util.Currency) ParseException(java.text.ParseException) ExpressionException(lucee.runtime.exp.ExpressionException) NumberFormat(java.text.NumberFormat) ParsePosition(java.text.ParsePosition)

Aggregations

Currency (java.util.Currency)60 Locale (java.util.Locale)21 BigDecimal (java.math.BigDecimal)8 NumberFormat (java.text.NumberFormat)8 DecimalFormat (java.text.DecimalFormat)7 DecimalFormatSymbols (java.text.DecimalFormatSymbols)7 ChoiceFormat (java.text.ChoiceFormat)3 HashSet (java.util.HashSet)3 JSONObject (com.alibaba.fastjson.JSONObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 ParsePosition (java.text.ParsePosition)2 ArrayList (java.util.ArrayList)2 Exchange (org.apache.camel.Exchange)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 ImmutableSet (com.google.common.collect.ImmutableSet)1