use of java.util.Currency in project jdk8u_jdk by JetBrains.
the class CurrencyTest method checkCountryCurrency.
static void checkCountryCurrency(String countryCode, String expected) {
Locale locale = new Locale("", countryCode);
Currency currency = Currency.getInstance(locale);
String code = (currency != null) ? currency.getCurrencyCode() : null;
if (!(expected == null ? code == null : expected.equals(code))) {
throw new RuntimeException("Wrong currency for " + locale.getDisplayCountry() + ": expected " + expected + ", got " + code);
}
}
use of java.util.Currency in project fastjson by alibaba.
the class CurrencyTest4 method test_0.
public void test_0() throws Exception {
JSONObject jsonObject = new JSONObject();
jsonObject.put("currency", "CNY");
String text = JSON.toJSONString(jsonObject);
Currency currency = JSON.parseObject(text, Currency.class);
assertSame(Currency.getInstance("CNY"), currency);
}
use of java.util.Currency in project fastjson by alibaba.
the class CurrencyTest4 method test_1.
public void test_1() throws Exception {
JSONObject jsonObject = new JSONObject();
jsonObject.put("symbol", "CNY");
String text = JSON.toJSONString(jsonObject);
Currency currency = JSON.parseObject(text, Currency.class);
assertSame(Currency.getInstance("CNY"), currency);
}
use of java.util.Currency in project adempiere by adempiere.
the class VSetup method dynInit.
// jbInit
/**
* Dynamic Init
*/
private void dynInit() {
// Using current locale for default values - teo_sarca [ 1691388 ]
Locale locale = Locale.getDefault();
Currency currency = Currency.getInstance(locale);
// Currency
// teo_sarca [ 1691388 ]
String sql = "SELECT C_Currency_ID, Description, ISO_Code FROM C_Currency ORDER BY 2";
Statement stmt = null;
ResultSet rs = null;
try {
stmt = DB.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
fCurrency.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2)));
// Currency from locale will be the default currency - teo_sarca [ 1691388 ]
if (currency != null && currency.getCurrencyCode().equals(rs.getString(3)))
fCurrency.setSelectedIndex(fCurrency.getItemCount() - 1);
}
} catch (SQLException e1) {
log.log(Level.SEVERE, "VSetup.dynInit -currency", e1);
} finally {
DB.close(rs, stmt);
rs = null;
stmt = null;
}
// Country
int C_Country_ID = 0;
// teo_sarca [ 1691388 ]
sql = "SELECT C_Country_ID, Name, CountryCode FROM C_Country ORDER BY 2";
try {
stmt = DB.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
fCountry.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2)));
// Country from locale will be the default country - teo_sarca [ 1691388 ]
if (locale.getCountry().equals(rs.getString(3))) {
fCountry.setSelectedIndex(fCountry.getItemCount() - 1);
C_Country_ID = rs.getInt(1);
}
}
} catch (SQLException e1) {
log.log(Level.SEVERE, "VSetup.dynInit -country", e1);
} finally {
DB.close(rs, stmt);
rs = null;
stmt = null;
}
// Region (optional)
sql = "SELECT C_Region_ID, Name, C_Country_ID FROM C_Region ORDER BY C_Country_ID, Name";
boolean isSelected = false;
try {
fRegion.addItem(new KeyNamePair(0, " "));
stmt = DB.createStatement();
rs = stmt.executeQuery(sql);
while (rs.next()) {
fRegion.addItem(new KeyNamePair(rs.getInt(1), rs.getString(2)));
// First region for selected country will be the default - teo_sarca [ 1691388 ]
if (!isSelected && rs.getInt(3) == C_Country_ID) {
fRegion.setSelectedIndex(fRegion.getItemCount() - 1);
isSelected = true;
}
}
} catch (SQLException e1) {
log.log(Level.SEVERE, "VSetup.dynInit -region", e1);
} finally {
DB.close(rs, stmt);
rs = null;
stmt = null;
}
// General Listeners
confirmPanel.addActionListener(this);
buttonLoadAcct.addActionListener(this);
confirmPanel.getOKButton().setEnabled(false);
}
use of java.util.Currency in project lucene-solr by apache.
the class CurrencyValue method parse.
/**
* Constructs a new currency value by parsing the specific input.
* <p/>
* Currency values are expected to be in the format <amount>,<currency code>,
* for example, "500,USD" would represent 5 U.S. Dollars.
* <p/>
* If no currency code is specified, the default is assumed.
*
* @param externalVal The value to parse.
* @param defaultCurrency The default currency.
* @return The parsed CurrencyValue.
*/
public static CurrencyValue parse(String externalVal, String defaultCurrency) {
if (externalVal == null) {
return null;
}
String amount = externalVal;
String code = defaultCurrency;
if (externalVal.contains(",")) {
String[] amountAndCode = externalVal.split(",");
amount = amountAndCode[0];
code = amountAndCode[1];
}
if (amount.equals("*")) {
return null;
}
Currency currency = CurrencyField.getCurrency(code);
if (currency == null) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Currency code not supported by this JVM: " + code);
}
try {
double value = Double.parseDouble(amount);
long currencyValue = Math.round(value * Math.pow(10.0, currency.getDefaultFractionDigits()));
return new CurrencyValue(currencyValue, code);
} catch (NumberFormatException e) {
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
}
}
Aggregations