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