Search in sources :

Example 56 with Currency

use of java.util.Currency in project robovm by robovm.

the class CurrencyTest method test_getDefaultFractionDigits.

/**
     * java.util.Currency#getDefaultFractionDigits()
     */
public void test_getDefaultFractionDigits() {
    Currency c1 = Currency.getInstance("TND");
    c1.getDefaultFractionDigits();
    assertEquals(" Currency.getInstance(\"" + c1 + "\") returned incorrect number of digits. ", 3, c1.getDefaultFractionDigits());
    Currency c2 = Currency.getInstance("EUR");
    c2.getDefaultFractionDigits();
    assertEquals(" Currency.getInstance(\"" + c2 + "\") returned incorrect number of digits. ", 2, c2.getDefaultFractionDigits());
    Currency c3 = Currency.getInstance("JPY");
    c3.getDefaultFractionDigits();
    assertEquals(" Currency.getInstance(\"" + c3 + "\") returned incorrect number of digits. ", 0, c3.getDefaultFractionDigits());
    Currency c4 = Currency.getInstance("XXX");
    c4.getDefaultFractionDigits();
    assertEquals(" Currency.getInstance(\"" + c4 + "\") returned incorrect number of digits. ", -1, c4.getDefaultFractionDigits());
}
Also used : Currency(java.util.Currency)

Example 57 with Currency

use of java.util.Currency in project robovm by robovm.

the class Main method testCurrency.

static void testCurrency() {
    Locale usa = new Locale("en", "US");
    Currency dollars = Currency.getInstance(usa);
    System.out.println(usa.toString() + ": " + dollars.toString() + " " + dollars.getSymbol() + dollars.getDefaultFractionDigits());
    Locale japan = new Locale("jp", "JP");
    Currency yen = Currency.getInstance(japan);
    System.out.println(japan.toString() + ": " + yen.toString() + " " + yen.getSymbol() + yen.getDefaultFractionDigits());
}
Also used : Locale(java.util.Locale) Currency(java.util.Currency)

Example 58 with Currency

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

the class CurrencyTest method testValidCurrency.

static void testValidCurrency(String currencyCode) {
    Currency currency1 = Currency.getInstance(currencyCode);
    Currency currency2 = Currency.getInstance(currencyCode);
    if (currency1 != currency2) {
        throw new RuntimeException("Didn't get same instance for same currency code");
    }
    if (!currency1.getCurrencyCode().equals(currencyCode)) {
        throw new RuntimeException("Currency code changed");
    }
}
Also used : Currency(java.util.Currency)

Example 59 with Currency

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

the class CurrencyValue method convertAmount.

/**
   * Performs a currency conversion & unit conversion.
   *
   * @param exchangeRate       Exchange rate to apply.
   * @param sourceCurrencyCode The source currency code.
   * @param sourceAmount       The source amount.
   * @param targetCurrencyCode The target currency code.
   * @return The converted indexable units after the exchange rate and currency fraction digits are applied.
   */
public static long convertAmount(double exchangeRate, String sourceCurrencyCode, long sourceAmount, String targetCurrencyCode) {
    if (targetCurrencyCode.equals(sourceCurrencyCode)) {
        return sourceAmount;
    }
    int sourceFractionDigits = Currency.getInstance(sourceCurrencyCode).getDefaultFractionDigits();
    Currency targetCurrency = Currency.getInstance(targetCurrencyCode);
    int targetFractionDigits = targetCurrency.getDefaultFractionDigits();
    return convertAmount(exchangeRate, sourceFractionDigits, sourceAmount, targetFractionDigits);
}
Also used : Currency(java.util.Currency)

Example 60 with Currency

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

the class LSCurrencyFormat method international.

public static String international(Locale locale, double 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;
}
Also used : Currency(java.util.Currency) NumberFormat(java.text.NumberFormat)

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