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());
}
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());
}
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");
}
}
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);
}
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;
}
Aggregations