// Even if parseIntegerOnly is set to true, NaN will be parsed to Double
form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
form.setParseIntegerOnly(true);
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
number = form.parse(symbols.getNaN(), new ParsePosition(0));
assertTrue(number instanceof Double);
// Even if parseIntegerOnly is set to true, Infinity will still be
// parsed to Double
form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
form.setParseIntegerOnly(true);
symbols = new DecimalFormatSymbols();
number = form.parse(symbols.getInfinity(), new ParsePosition(0));
assertTrue(number instanceof Double);
// ParseBigDecimal take precedence of parseBigInteger
form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
form.setParseIntegerOnly(true);
form.setParseBigDecimal(true);
number = form.parse("23.1f", new ParsePosition(0));
assertTrue(number instanceof BigDecimal);
number = form.parse("23.0", new ParsePosition(0));
assertTrue(number instanceof BigDecimal);
number = form.parse("-9,223,372,036,854,775,8080.00",
new ParsePosition(0));
assertFalse(number instanceof BigInteger);
assertTrue(number instanceof BigDecimal);
// Test whether the parsed object is of type float. (To be specific,
// they are of type Double)
form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
number = form.parse("23.1f", new ParsePosition(0));
assertTrue(number instanceof Double);
form.setParseBigDecimal(true);
number = form.parse("23.1f", new ParsePosition(0));
assertTrue(number instanceof BigDecimal);
assertEquals(new BigDecimal("23.1"), number);
// Integer will be parsed to Long, unless parseBigDecimal is set to true
form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
number = form.parse("123", new ParsePosition(0));
assertTrue(number instanceof Long);
form.setParseBigDecimal(true);
number = form.parse("123", new ParsePosition(0));
assertTrue(number instanceof BigDecimal);
assertEquals(new BigDecimal("123"), number);
// NaN will be parsed to Double, no matter parseBigDecimal set or not.
form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
symbols = new DecimalFormatSymbols();
number = form.parse(symbols.getNaN() + "", new ParsePosition(0));
assertTrue(number instanceof Double);
form.setParseBigDecimal(true);
number = form.parse(symbols.getNaN() + "", new ParsePosition(0));
assertTrue(number instanceof Double);
// Infinity will be parsed to Double, no matter parseBigDecimal set or
// not.
form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
symbols = new DecimalFormatSymbols();
number = form.parse(symbols.getInfinity(), new ParsePosition(0));
assertTrue(number instanceof Double);
assertEquals("Infinity", number.toString());
// When set bigDecimal to true, the result of parsing infinity
form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
symbols = new DecimalFormatSymbols();
form.setParseBigDecimal(true);
number = form.parse(symbols.getInfinity(), new ParsePosition(0));
assertTrue(number instanceof Double);
assertEquals("Infinity", number.toString());
// Negative infinity will be parsed to double no matter parseBigDecimal
// set or not
form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
symbols = new DecimalFormatSymbols();
number = form.parse("-" + symbols.getInfinity(), new ParsePosition(0));
assertTrue(number instanceof Double);
assertEquals("-Infinity", number.toString());
// When set bigDecimal to true, the result of parsing minus infinity
form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
symbols = new DecimalFormatSymbols();
form.setParseBigDecimal(true);
number = form.parse("-" + symbols.getInfinity(), new ParsePosition(0));
assertTrue(number instanceof Double);
assertEquals("-Infinity", number.toString());
// -0.0 will be parsed to different type according to the combination of