use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_parse_bigDecimal.
public void test_parse_bigDecimal() throws Exception {
// parseBigDecimal default to false
DecimalFormat form = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
assertFalse(form.isParseBigDecimal());
form.setParseBigDecimal(true);
assertTrue(form.isParseBigDecimal());
Number result = form.parse("123.123");
assertEquals(new BigDecimal("123.123"), result);
form.setParseBigDecimal(false);
assertFalse(form.isParseBigDecimal());
result = form.parse("123.123");
assertFalse(result instanceof BigDecimal);
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_setNegativeSuffix.
public void test_setNegativeSuffix() throws Exception {
DecimalFormat format = new DecimalFormat();
assertEquals("", format.getNegativeSuffix());
format.setNegativeSuffix("NegSfx");
assertEquals("NegSfx", format.getNegativeSuffix());
assertTrue(format.parse("123.45NegPfx").doubleValue() == 123.45);
format.setNegativeSuffix("");
assertEquals("", format.getNegativeSuffix());
format.setNegativeSuffix(null);
assertNull(format.getNegativeSuffix());
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_formatDouble_roundingTo15Digits.
// This demonstrates rounding at the 15th decimal digit. By setting the maximum fraction digits
// we force rounding at a point just below the full IEEE 754 precision. IEEE 754 should be
// precise to just above 15 decimal digits.
// df.format() with no limits always emits up to 16 decimal digits, slightly above what IEEE 754
// can store precisely.
public void test_formatDouble_roundingTo15Digits() throws Exception {
final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
DecimalFormat df = new DecimalFormat("#.#", dfs);
df.setMaximumIntegerDigits(400);
df.setGroupingUsed(false);
df.setMaximumFractionDigits(0);
assertEquals("1000000000000000", df.format(999999999999999.9));
df.setMaximumFractionDigits(1);
assertEquals("100000000000000", df.format(99999999999999.99));
df.setMaximumFractionDigits(2);
assertEquals("10000000000000", df.format(9999999999999.999));
df.setMaximumFractionDigits(3);
assertEquals("1000000000000", df.format(999999999999.9999));
df.setMaximumFractionDigits(4);
assertEquals("100000000000", df.format(99999999999.99999));
df.setMaximumFractionDigits(5);
assertEquals("10000000000", df.format(9999999999.999999));
df.setMaximumFractionDigits(6);
assertEquals("1000000000", df.format(999999999.9999999));
df.setMaximumFractionDigits(7);
assertEquals("100000000", df.format(99999999.99999999));
df.setMaximumFractionDigits(8);
assertEquals("10000000", df.format(9999999.999999999));
df.setMaximumFractionDigits(9);
assertEquals("1000000", df.format(999999.9999999999));
df.setMaximumFractionDigits(10);
assertEquals("100000", df.format(99999.99999999999));
df.setMaximumFractionDigits(11);
assertEquals("10000", df.format(9999.999999999999));
df.setMaximumFractionDigits(12);
assertEquals("1000", df.format(999.9999999999999));
df.setMaximumFractionDigits(13);
assertEquals("100", df.format(99.99999999999999));
df.setMaximumFractionDigits(14);
assertEquals("10", df.format(9.999999999999999));
df.setMaximumFractionDigits(15);
assertEquals("1", df.format(0.9999999999999999));
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_clone.
public void test_clone() {
DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(Locale.US);
DecimalFormat cloned = (DecimalFormat) format.clone();
assertEquals(cloned.getDecimalFormatSymbols(), format.getDecimalFormatSymbols());
format = new DecimalFormat("'$'0000.0000");
DecimalFormat format1 = (DecimalFormat) (format.clone());
// make sure the objects are equal
assertTrue("Object's clone isn't equal!", format.equals(format1));
// change the content of the clone and make sure it's not equal anymore
// verifies that it's data is now distinct from the original
format1.applyPattern("'$'0000.####");
assertTrue("Object's changed clone should not be equal!", !format.equals(format1));
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method testConstructor_noArg.
public void testConstructor_noArg() {
// Test for method java.text.DecimalFormat()
// the constructor form that specifies a pattern is equal to the form
// constructed with no pattern and applying that pattern using the
// applyPattern call
DecimalFormat format1 = new DecimalFormat();
format1.applyPattern("'$'1000.0000");
DecimalFormat format2 = new DecimalFormat();
format2.applyPattern("'$'1000.0000");
assertTrue("Constructed format did not match applied format object", format2.equals(format1));
DecimalFormat format3 = new DecimalFormat("'$'1000.0000");
assertTrue("Constructed format did not match applied format object", format3.equals(format1));
DecimalFormat format4 = new DecimalFormat("'$'8000.0000");
assertTrue("Constructed format did not match applied format object", !format4.equals(format1));
}
Aggregations