use of android.icu.util.Currency in project j2objc by google.
the class DecimalFormat method setCurrencyUsage.
/**
* Sets the <tt>Currency Usage</tt> object used to display currency.
* This takes effect immediately, if this format is a
* currency format.
* @param newUsage new currency context object to use.
*/
public void setCurrencyUsage(CurrencyUsage newUsage) {
if (newUsage == null) {
throw new NullPointerException("return value is null at method AAA");
}
currencyUsage = newUsage;
Currency theCurrency = this.getCurrency();
// We set rounding/digit based on currency context
if (theCurrency != null) {
setRoundingIncrement(theCurrency.getRoundingIncrement(currencyUsage));
int d = theCurrency.getDefaultFractionDigits(currencyUsage);
setMinimumFractionDigits(d);
_setMaximumFractionDigits(d);
}
}
use of android.icu.util.Currency in project j2objc by google.
the class NumberFormatTest method TestCurrency.
/**
* Test localized currency patterns.
*/
@Test
public void TestCurrency() {
String[] DATA = { "fr", "CA", "", "1,50\u00a0$", "de", "DE", "", "1,50\u00a0\u20AC", "de", "DE", "PREEURO", "1,50\u00a0DM", "fr", "FR", "", "1,50\u00a0\u20AC", "fr", "FR", "PREEURO", "1,50\u00a0F" };
for (int i = 0; i < DATA.length; i += 4) {
Locale locale = new Locale(DATA[i], DATA[i + 1], DATA[i + 2]);
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
String s = fmt.format(1.50);
if (s.equals(DATA[i + 3])) {
logln("Ok: 1.50 x " + locale + " => " + s);
} else {
logln("FAIL: 1.50 x " + locale + " => " + s + ", expected " + DATA[i + 3]);
}
}
// format currency with CurrencyAmount
for (int i = 0; i < DATA.length; i += 4) {
Locale locale = new Locale(DATA[i], DATA[i + 1], DATA[i + 2]);
Currency curr = Currency.getInstance(locale);
logln("\nName of the currency is: " + curr.getName(locale, Currency.LONG_NAME, new boolean[] { false }));
CurrencyAmount cAmt = new CurrencyAmount(1.5, curr);
// cover hashCode
logln("CurrencyAmount object's hashCode is: " + cAmt.hashCode());
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
String sCurr = fmt.format(cAmt);
if (sCurr.equals(DATA[i + 3])) {
logln("Ok: 1.50 x " + locale + " => " + sCurr);
} else {
errln("FAIL: 1.50 x " + locale + " => " + sCurr + ", expected " + DATA[i + 3]);
}
}
// Cover MeasureFormat.getCurrencyFormat()
ULocale save = ULocale.getDefault();
ULocale.setDefault(ULocale.US);
MeasureFormat curFmt = MeasureFormat.getCurrencyFormat();
String strBuf = curFmt.format(new CurrencyAmount(new Float(1234.56), Currency.getInstance("USD")));
try {
CurrencyAmount parsedVal = (CurrencyAmount) curFmt.parseObject(strBuf);
Number val = parsedVal.getNumber();
if (!val.equals(new BigDecimal("1234.56"))) {
errln("FAIL: getCurrencyFormat of default locale (en_US) failed roundtripping the number. val=" + val);
}
if (!parsedVal.getCurrency().equals(Currency.getInstance("USD"))) {
errln("FAIL: getCurrencyFormat of default locale (en_US) failed roundtripping the currency");
}
} catch (ParseException e) {
errln("FAIL: " + e.getMessage());
}
ULocale.setDefault(save);
}
use of android.icu.util.Currency in project j2objc by google.
the class NumberFormatTest method TestJB3832.
@Test
public void TestJB3832() {
ULocale locale = new ULocale("pt_PT@currency=PTE");
NumberFormat format = NumberFormat.getCurrencyInstance(locale);
Currency curr = Currency.getInstance(locale);
logln("\nName of the currency is: " + curr.getName(locale, Currency.LONG_NAME, new boolean[] { false }));
CurrencyAmount cAmt = new CurrencyAmount(1150.50, curr);
// cover hashCode
logln("CurrencyAmount object's hashCode is: " + cAmt.hashCode());
String str = format.format(cAmt);
String expected = "1,150$50\u00a0\u200b";
if (!expected.equals(str)) {
errln("Did not get the expected output Expected: " + expected + " Got: " + str);
}
}
use of android.icu.util.Currency in project j2objc by google.
the class NumberFormatTest method TestSetCurrency.
@Test
public void TestSetCurrency() {
DecimalFormatSymbols decf1 = DecimalFormatSymbols.getInstance(ULocale.US);
DecimalFormatSymbols decf2 = DecimalFormatSymbols.getInstance(ULocale.US);
decf2.setCurrencySymbol("UKD");
DecimalFormat format1 = new DecimalFormat("000.000", decf1);
DecimalFormat format2 = new DecimalFormat("000.000", decf2);
Currency euro = Currency.getInstance("EUR");
format1.setCurrency(euro);
format2.setCurrency(euro);
assertEquals("Reset with currency symbol", format1, format2);
}
use of android.icu.util.Currency in project j2objc by google.
the class NumberFormatTest method TestCurrencyPatterns.
@Test
public void TestCurrencyPatterns() {
int i;
Locale[] locs = NumberFormat.getAvailableLocales();
for (i = 0; i < locs.length; ++i) {
NumberFormat nf = NumberFormat.getCurrencyInstance(locs[i]);
// Make sure currency formats do not have a variable number
// of fraction digits
int min = nf.getMinimumFractionDigits();
int max = nf.getMaximumFractionDigits();
if (min != max) {
String a = nf.format(1.0);
String b = nf.format(1.125);
errln("FAIL: " + locs[i] + " min fraction digits != max fraction digits; " + "x 1.0 => " + a + "; x 1.125 => " + b);
}
// Make sure EURO currency formats have exactly 2 fraction digits
if (nf instanceof DecimalFormat) {
Currency curr = ((DecimalFormat) nf).getCurrency();
if (curr != null && "EUR".equals(curr.getCurrencyCode())) {
if (min != 2 || max != 2) {
String a = nf.format(1.0);
errln("FAIL: " + locs[i] + " is a EURO format but it does not have 2 fraction digits; " + "x 1.0 => " + a);
}
}
}
}
}
Aggregations