use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method testMaximumFactionDigits_maxChangesMin.
// When MinFractionDigits is set first and less than MaxFractionDigits, min
// will be changed to max value
public void testMaximumFactionDigits_maxChangesMin() {
DecimalFormat form = (DecimalFormat) NumberFormat.getInstance(Locale.US);
form.setMinimumFractionDigits(200);
form.setMaximumFractionDigits(100);
assertEquals(100, form.getMaximumFractionDigits());
assertEquals(100, form.getMinimumFractionDigits());
form.setMinimumIntegerDigits(200);
form.setMaximumIntegerDigits(100);
assertEquals(100, form.getMaximumIntegerDigits());
assertEquals(100, form.getMinimumIntegerDigits());
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_setCurrency.
public void test_setCurrency() {
Locale locale = Locale.CANADA;
DecimalFormat df = ((DecimalFormat) NumberFormat.getCurrencyInstance(locale));
try {
df.setCurrency(null);
fail("Expected NullPointerException");
} catch (NullPointerException e) {
}
Currency currency = Currency.getInstance("AED");
df.setCurrency(currency);
assertTrue("Returned incorrect currency", currency == df.getCurrency());
assertEquals("Returned incorrect currency symbol", currency.getSymbol(locale), df.getDecimalFormatSymbols().getCurrencySymbol());
assertEquals("Returned incorrect international currency symbol", currency.getCurrencyCode(), df.getDecimalFormatSymbols().getInternationalCurrencySymbol());
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_setDecimalSeparatorAlwaysShown.
public void test_setDecimalSeparatorAlwaysShown() {
DecimalFormat df = new DecimalFormat("###0.##", new DecimalFormatSymbols(Locale.US));
assertEquals("Wrong default result", "5", df.format(5));
df.setDecimalSeparatorAlwaysShown(true);
assertTrue("Not set", df.isDecimalSeparatorAlwaysShown());
assertEquals("Wrong set result", "7.", df.format(7));
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_toPattern.
public void test_toPattern() {
DecimalFormat format = new DecimalFormat();
format.applyPattern("#.#");
assertEquals("Wrong pattern 1", "#0.#", format.toPattern());
format.applyPattern("#.");
assertEquals("Wrong pattern 2", "#0.", format.toPattern());
format.applyPattern("#");
assertEquals("Wrong pattern 3", "#", format.toPattern());
format.applyPattern(".#");
assertEquals("Wrong pattern 4", "#.0", format.toPattern());
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_setDecimalFormatSymbols.
/* J2ObjC: Android behavior differs from RI.
public void test_parse_withMultiplier() {
DecimalFormat format = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
Number result;
format.setMultiplier(100);
result = format.parse("9223372036854775807", new ParsePosition(0));
assertEquals("Wrong result type multiplier 100: " + result, Double.class,
result.getClass());
assertEquals("Wrong result for multiplier 100: " + result,
92233720368547758.07d, result.doubleValue());
format.setMultiplier(1000);
result = format.parse("9223372036854775807", new ParsePosition(0));
assertEquals("Wrong result type multiplier 1000: " + result, Double.class,
result.getClass());
assertEquals("Wrong result for multiplier 1000: " + result,
9223372036854775.807d, result.doubleValue());
format.setMultiplier(10000);
result = format.parse("9223372036854775807", new ParsePosition(0));
assertEquals("Wrong result type multiplier 10000: " + result,
Double.class, result.getClass());
assertEquals("Wrong result for multiplier 10000: " + result,
922337203685477.5807d, result.doubleValue());
}*/
public void test_setDecimalFormatSymbols() {
DecimalFormat df = new DecimalFormat("###0.##");
DecimalFormatSymbols dfs = new DecimalFormatSymbols();
dfs.setDecimalSeparator('@');
df.setDecimalFormatSymbols(dfs);
assertTrue("Not set", df.getDecimalFormatSymbols().equals(dfs));
assertEquals("Symbols not used", "1@2", df.format(1.2));
// The returned symbols may be cloned in two spots
// 1. When set
// 2. When returned
DecimalFormat format = new DecimalFormat();
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
format.setDecimalFormatSymbols(symbols);
DecimalFormatSymbols symbolsOut = format.getDecimalFormatSymbols();
assertNotSame(symbols, symbolsOut);
}
Aggregations