use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_setDecimalFormatSymbolsAsNull.
public void test_setDecimalFormatSymbolsAsNull() {
// Regression for HARMONY-1070
DecimalFormat format = (DecimalFormat) NumberFormat.getInstance();
format.setDecimalFormatSymbols(null);
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method testMinimumIntegerDigits_getAndSet.
public void testMinimumIntegerDigits_getAndSet() {
final int minIntDigit = 1;
DecimalFormat form = (DecimalFormat) NumberFormat.getInstance(Locale.US);
// getMaximumIntegerDigits from DecimalFormat (default to 1)
assertEquals(minIntDigit, form.getMinimumIntegerDigits());
form.setMinimumIntegerDigits(300);
assertEquals(300, form.getMinimumIntegerDigits());
// Deliberately > 309. The API docs mention 309 and suggest that you can set the value
// higher but it will use 309 as a ceiling.
form.setMinimumIntegerDigits(500);
assertEquals(500, form.getMinimumIntegerDigits());
form.setMaximumIntegerDigits(400);
assertEquals(400, form.getMinimumIntegerDigits());
form.setMinimumIntegerDigits(-3);
assertEquals(0, form.getMinimumIntegerDigits());
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_applyPattern.
public void test_applyPattern() {
DecimalFormat format = new DecimalFormat("#.#");
assertEquals("Wrong pattern 1", "#0.#", format.toPattern());
format = new DecimalFormat("#.");
assertEquals("Wrong pattern 2", "#0.", format.toPattern());
format = new DecimalFormat("#");
assertEquals("Wrong pattern 3", "#", format.toPattern());
format = new DecimalFormat(".#");
assertEquals("Wrong pattern 4", "#.0", format.toPattern());
// Regression for HARMONY-6485
format = new DecimalFormat();
format.setMinimumIntegerDigits(0);
format.setMinimumFractionDigits(0);
format.setMaximumFractionDigits(0);
format.applyPattern("00.0#");
assertEquals("Minimum integer digits not set", 2, format.getMinimumIntegerDigits());
assertEquals("Minimum fraction digits not set", 1, format.getMinimumFractionDigits());
assertEquals("Maximum fraction digits not set", 2, format.getMaximumFractionDigits());
try {
format.applyPattern(null);
fail();
} catch (NullPointerException expected) {
}
try {
format.applyPattern("%#,##,###,####'");
fail();
} catch (IllegalArgumentException expected) {
}
try {
format.applyPattern("#.##0.00");
fail();
} catch (IllegalArgumentException expected) {
}
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_formatToCharacterIterator_roundingUnnecessaryArithmeticException.
public void test_formatToCharacterIterator_roundingUnnecessaryArithmeticException() {
DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
decimalFormat.setRoundingMode(RoundingMode.UNNECESSARY);
decimalFormat.setMaximumFractionDigits(0);
try {
// when rounding is needed, but RoundingMode is set to RoundingMode.UNNECESSARY,
// throw ArithmeticException
decimalFormat.formatToCharacterIterator(new Double(1.5));
fail("ArithmeticException expected");
} catch (ArithmeticException e) {
// expected
}
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_getMultiplier.
public void test_getMultiplier() {
final int defaultMultiplier = 1;
DecimalFormat form = (DecimalFormat) NumberFormat.getInstance(Locale.US);
assertEquals(defaultMultiplier, form.getMultiplier());
DecimalFormat df = new DecimalFormat("###0.##");
assertEquals("Wrong unset multiplier", 1, df.getMultiplier());
df = new DecimalFormat("###0.##%");
assertEquals("Wrong percent multiplier", 100, df.getMultiplier());
df = new DecimalFormat("###0.##‰");
assertEquals("Wrong mille multiplier", 1000, df.getMultiplier());
}
Aggregations