use of java.text.DecimalFormatSymbols in project j2objc by google.
the class DecimalFormatTest method test_toLocalizedPattern.
public void test_toLocalizedPattern() {
DecimalFormat format = new DecimalFormat();
format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
format.applyLocalizedPattern("#.#");
assertEquals("Wrong pattern 1", "#0.#", format.toLocalizedPattern());
format.applyLocalizedPattern("#.");
assertEquals("Wrong pattern 2", "#0.", format.toLocalizedPattern());
format.applyLocalizedPattern("#");
assertEquals("Wrong pattern 3", "#", format.toLocalizedPattern());
format.applyLocalizedPattern(".#");
assertEquals("Wrong pattern 4", "#.0", format.toLocalizedPattern());
}
use of java.text.DecimalFormatSymbols in project j2objc by google.
the class DecimalFormatTest method test_setGroupingSize.
public void test_setGroupingSize() {
DecimalFormat df = new DecimalFormat("###0.##", new DecimalFormatSymbols(Locale.ENGLISH));
df.setGroupingUsed(true);
df.setGroupingSize(2);
assertEquals("Value not set", 2, df.getGroupingSize());
String result = df.format(123);
assertTrue("Invalid format:" + result, result.equals("1,23"));
}
use of java.text.DecimalFormatSymbols in project j2objc by google.
the class DecimalFormatTest method test_formatDouble_minimumFractionDigits.
public void test_formatDouble_minimumFractionDigits() {
DecimalFormat df = new DecimalFormat("###0.##", new DecimalFormatSymbols(Locale.US));
df.setMinimumFractionDigits(4);
assertEquals(4, df.getMinimumFractionDigits());
assertEquals("1.2300", df.format(1.23));
df.setMaximumFractionDigits(2);
assertEquals(2, df.getMinimumFractionDigits());
assertEquals("456.00", df.format(456));
df = new DecimalFormat("##0.#", new DecimalFormatSymbols(Locale.US));
df.setMinimumFractionDigits(30);
assertEquals("0.000000000000000000000000000000", df.format(0.0));
assertEquals("-0.000000000000000000000000000000", df.format(-0.0));
assertEquals("1.000000000000000000000000000000", df.format(1.0));
assertEquals("-1.000000000000000000000000000000", df.format(-1.0));
}
use of java.text.DecimalFormatSymbols in project j2objc by google.
the class DecimalFormatTest method test_getDecimalFormatSymbols.
// Concise demonstration of http://b/17656132 using hard-coded expected values.
/* J2ObjC: This test is actually a demonstration of a bug.
public void test_formatDouble_bug17656132() {
final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
DecimalFormat df = new DecimalFormat("#0.#", dfs);
df.setGroupingUsed(false);
df.setMaximumIntegerDigits(400);
df.setMaximumFractionDigits(400);
// The expected values below come from the RI and are correct 16 decimal digit
// representations of the formatted value. Android does something different.
// The decimal value given in each comment is the actual double value as represented by
// IEEE 754. See new BigDecimal(double).
// double: 999999999999999.9 is decimal 999999999999999.875
assertEquals("999999999999999.9", df.format(999999999999999.9));
// double: 99999999999999.98 is decimal 99999999999999.984375
assertEquals("99999999999999.98", df.format(99999999999999.98));
// double 9999999999999.998 is decimal 9999999999999.998046875
assertEquals("9999999999999.998", df.format(9999999999999.998));
// double 999999999999.9999 is decimal 999999999999.9998779296875
assertEquals("999999999999.9999", df.format(999999999999.9999));
// double 99999999999.99998 is decimal 99999999999.9999847412109375
assertEquals("99999999999.99998", df.format(99999999999.99998));
// double 9999999999.999998 is decimal 9999999999.9999980926513671875
assertEquals("9999999999.999998", df.format(9999999999.999998));
// double 1E23 is decimal 99999999999999991611392
assertEquals("9999999999999999", df.format(1E23));
}*/
public void test_getDecimalFormatSymbols() {
DecimalFormat df = (DecimalFormat) NumberFormat.getInstance(Locale.ENGLISH);
DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
assertNotSame(dfs, df.getDecimalFormatSymbols());
}
use of java.text.DecimalFormatSymbols in project j2objc by google.
the class DecimalFormatSymbolsTest method test_setInternationalCurrencySymbolLjava_lang_String.
/**
* @tests java.text.DecimalFormatSymbols#setInternationalCurrencySymbol(java.lang.String)
*/
public void test_setInternationalCurrencySymbolLjava_lang_String() {
Locale locale = Locale.CANADA;
DecimalFormatSymbols dfs = ((DecimalFormat) NumberFormat.getCurrencyInstance(locale)).getDecimalFormatSymbols();
Currency currency = Currency.getInstance("JPY");
dfs.setInternationalCurrencySymbol(currency.getCurrencyCode());
assertTrue("Test1: Returned incorrect currency", currency == dfs.getCurrency());
assertEquals("Test1: Returned incorrect currency symbol", currency.getSymbol(locale), dfs.getCurrencySymbol());
assertTrue("Test1: Returned incorrect international currency symbol", currency.getCurrencyCode().equals(dfs.getInternationalCurrencySymbol()));
dfs.setInternationalCurrencySymbol("bogus");
// RI support this legacy country code
// assertNotNull("Test2: Returned incorrect currency", dfs.getCurrency());
assertEquals("Test2: Returned incorrect international currency symbol", "bogus", dfs.getInternationalCurrencySymbol());
}
Aggregations