use of java.util.Currency in project j2objc by google.
the class NumberFormatTest method test_getCurrency.
/**
* @tests java.text.NumberFormat#getCurrency()
*/
public void test_getCurrency() {
// Test for method java.util.Currency getCurrency()
// a subclass that supports currency formatting
Currency currH = Currency.getInstance("HUF");
NumberFormat format = NumberFormat.getInstance(new Locale("hu", "HU"));
assertSame("Returned incorrect currency", currH, format.getCurrency());
// a subclass that doesn't support currency formatting
ChoiceFormat cformat = new ChoiceFormat("0#Less than one|1#one|1<Between one and two|2<Greater than two");
try {
((NumberFormat) cformat).getCurrency();
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
}
}
use of java.util.Currency in project j2objc by google.
the class DecimalFormatSymbolsTest method testSetNulInternationalCurrencySymbol.
// // https://code.google.com/p/android/issues/detail?id=79925
// public void testSetSameCurrency() throws Exception {
// DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
// dfs.setCurrency(Currency.getInstance("USD"));
// assertEquals("$", dfs.getCurrencySymbol());
// dfs.setCurrencySymbol("poop");
// assertEquals("poop", dfs.getCurrencySymbol());
// dfs.setCurrency(Currency.getInstance("USD"));
// assertEquals("$", dfs.getCurrencySymbol());
// }
public void testSetNulInternationalCurrencySymbol() throws Exception {
Currency usd = Currency.getInstance("USD");
DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
dfs.setCurrency(usd);
assertEquals(usd, dfs.getCurrency());
assertEquals("$", dfs.getCurrencySymbol());
assertEquals("USD", dfs.getInternationalCurrencySymbol());
// Setting the international currency symbol to null sets the currency to null too,
// but not the currency symbol.
dfs.setInternationalCurrencySymbol(null);
assertEquals(null, dfs.getCurrency());
assertEquals("$", dfs.getCurrencySymbol());
assertEquals(null, dfs.getInternationalCurrencySymbol());
}
use of java.util.Currency in project j2objc by google.
the class DecimalFormatTest method testSetCurrency_symbolOrigin.
// Confirm the currency symbol used by a format is determined by the locale of the format
// not the current default Locale.
public void testSetCurrency_symbolOrigin() {
Currency currency = Currency.getInstance("CNY");
Locale locale1 = Locale.CHINA;
Locale locale2 = Locale.US;
String locale1Symbol = currency.getSymbol(locale1);
String locale2Symbol = currency.getSymbol(locale2);
// This test only works if we can tell where the symbol came from, which requires they are
// different across the two locales chosen.
assertFalse(locale1Symbol.equals(locale2Symbol));
Locale originalLocale = Locale.getDefault();
try {
Locale.setDefault(locale1);
String amountDefaultLocale1 = formatArbitraryCurrencyAmountInLocale(currency, locale2);
Locale.setDefault(locale2);
String amountDefaultLocale2 = formatArbitraryCurrencyAmountInLocale(currency, locale2);
// This used to fail because Currency.getSymbol() was used without providing the
// format's locale.
assertEquals(amountDefaultLocale1, amountDefaultLocale2);
} finally {
Locale.setDefault(originalLocale);
}
}
use of java.util.Currency in project cordova-android-chromeview by thedracle.
the class Globalization method getCurrencyPattern.
/*
* @Description: Returns a pattern string for formatting and parsing currency values according to the client's
* user preferences and ISO 4217 currency code.
* @Return: JSONObject
* Object.pattern {String}: The currency pattern for formatting and parsing currency values.
* The patterns follow Unicode Technical Standard #35
* http://unicode.org/reports/tr35/tr35-4.html
* Object.code {String}: The ISO 4217 currency code for the pattern.
* Object.fraction {Number}: The number of fractional digits to use when parsing and
* formatting currency.
* Object.rounding {Number}: The rounding increment to use when parsing and formatting.
* Object.decimal: {String}: The decimal symbol to use for parsing and formatting.
* Object.grouping: {String}: The grouping symbol to use for parsing and formatting.
*
* @throws: GlobalizationError.FORMATTING_ERROR
*/
private JSONObject getCurrencyPattern(JSONArray options) throws GlobalizationError {
JSONObject obj = new JSONObject();
try {
//get ISO 4217 currency code
String code = options.getJSONObject(0).getString(CURRENCYCODE);
//uses java.text.DecimalFormat to format value
DecimalFormat fmt = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.getDefault());
//set currency format
Currency currency = Currency.getInstance(code);
fmt.setCurrency(currency);
//return properties
obj.put("pattern", fmt.toPattern());
obj.put("code", currency.getCurrencyCode());
obj.put("fraction", fmt.getMinimumFractionDigits());
obj.put("rounding", new Integer(0));
obj.put("decimal", String.valueOf(fmt.getDecimalFormatSymbols().getDecimalSeparator()));
obj.put("grouping", String.valueOf(fmt.getDecimalFormatSymbols().getGroupingSeparator()));
return obj;
} catch (Exception ge) {
throw new GlobalizationError(GlobalizationError.FORMATTING_ERROR);
}
}
use of java.util.Currency in project Botnak by Gocnak.
the class DonationManager method checkDonations.
public void checkDonations(boolean single) {
int limit = (single ? 5 : 100);
String url = "https://streamtip.com/api/tips?client_id=" + getClientID() + "&access_token=" + getAccessCode() + "&limit=" + limit;
try {
String line = Utils.createAndParseBufferedReader(new URL(url).openStream());
if (!line.isEmpty()) {
JSONObject outerShell = new JSONObject(line);
int status = outerShell.getInt("status");
int count = outerShell.getInt("_count");
if (status == 200) {
//ensure there's no problem with the site
JSONArray tipsArray = outerShell.getJSONArray("tips");
for (int i = (single ? tipsArray.length() - 1 : count - 1); i > -1; i--) {
JSONObject tip = tipsArray.getJSONObject(i);
try {
Currency c = Currency.getInstance(tip.getString("currencyCode"));
getCurrencyFormat().setCurrency(c);
} catch (Exception e) {
GUIMain.log("Unknown currency code: " + tip.getString("currencyCode"));
getCurrencyFormat().setCurrency(Currency.getInstance("USD"));
}
if (lastDonation != null) {
if (lastDonation.getDonationID().equals(tip.getString("_id"))) {
continue;
}
}
addDonation(tip, false);
}
}
}
} catch (Exception e) {
GUIMain.log(e);
}
}
Aggregations