use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_formatLong_minimumIntegerDigits.
public void test_formatLong_minimumIntegerDigits() {
DecimalFormat df = new DecimalFormat("###0.##", new DecimalFormatSymbols(Locale.US));
df.setMinimumIntegerDigits(3);
assertEquals(3, df.getMinimumIntegerDigits());
assertEquals("012", df.format(12));
df.setMaximumIntegerDigits(2);
assertEquals(2, df.getMinimumIntegerDigits());
assertEquals("00.7", df.format(0.7));
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_parse_withParsePosition.
public void test_parse_withParsePosition() {
DecimalFormat format = (DecimalFormat) NumberFormat.getNumberInstance(Locale.ENGLISH);
ParsePosition pos = new ParsePosition(0);
Number result = format.parse("9223372036854775807", pos);
assertTrue("Wrong result type for Long.MAX_VALUE", result.getClass() == Long.class);
assertTrue("Wrong result Long.MAX_VALUE", result.longValue() == Long.MAX_VALUE);
pos = new ParsePosition(0);
result = format.parse("-9223372036854775808", pos);
assertTrue("Wrong result type for Long.MIN_VALUE", result.getClass() == Long.class);
assertTrue("Wrong result Long.MIN_VALUE: " + result.longValue(), result.longValue() == Long.MIN_VALUE);
pos = new ParsePosition(0);
result = format.parse("9223372036854775808", pos);
assertTrue("Wrong result type for Long.MAX_VALUE+1", result.getClass() == Double.class);
assertTrue("Wrong result Long.MAX_VALUE + 1", result.doubleValue() == (double) Long.MAX_VALUE + 1);
pos = new ParsePosition(0);
result = format.parse("-9223372036854775809", pos);
assertTrue("Wrong result type for Long.MIN_VALUE+1", result.getClass() == Double.class);
assertTrue("Wrong result Long.MIN_VALUE - 1", result.doubleValue() == (double) Long.MIN_VALUE - 1);
pos = new ParsePosition(0);
result = format.parse("18446744073709551629", pos);
assertTrue("Wrong result type for overflow", result.getClass() == Double.class);
assertTrue("Wrong result for overflow", result.doubleValue() == 18446744073709551629d);
pos = new ParsePosition(0);
result = format.parse("42325917317067571199", pos);
assertTrue("Wrong result type for overflow a: " + result, result.getClass() == Double.class);
assertTrue("Wrong result for overflow a: " + result, result.doubleValue() == 42325917317067571199d);
pos = new ParsePosition(0);
result = format.parse("4232591731706757119E1", pos);
assertTrue("Wrong result type for overflow b: " + result, result.getClass() == Double.class);
assertTrue("Wrong result for overflow b: " + result, result.doubleValue() == 42325917317067571190d);
pos = new ParsePosition(0);
result = format.parse(".42325917317067571199E20", pos);
assertTrue("Wrong result type for overflow c: " + result, result.getClass() == Double.class);
assertTrue("Wrong result for overflow c: " + result, result.doubleValue() == 42325917317067571199d);
pos = new ParsePosition(0);
result = format.parse("922337203685477580.9E1", pos);
assertTrue("Wrong result type for overflow d: " + result, result.getClass() == Double.class);
assertTrue("Wrong result for overflow d: " + result, result.doubleValue() == 9223372036854775809d);
pos = new ParsePosition(0);
result = format.parse("9.223372036854775809E18", pos);
assertTrue("Wrong result type for overflow e: " + result, result.getClass() == Double.class);
assertTrue("Wrong result for overflow e: " + result, result.doubleValue() == 9223372036854775809d);
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_getNegativeSuffix.
public void test_getNegativeSuffix() {
DecimalFormat df = new DecimalFormat();
df.setNegativeSuffix("&");
assertTrue("Incorrect negative suffix", df.getNegativeSuffix().equals("&"));
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_getPositiveSuffix.
public void test_getPositiveSuffix() {
DecimalFormat df = new DecimalFormat();
df.setPositiveSuffix("%");
assertTrue("Incorrect positive prefix", df.getPositiveSuffix().equals("%"));
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method testConstructor_stringAndSymbols.
public void testConstructor_stringAndSymbols() {
// case 1: Try to construct object using correct pattern and format
// symbols.
DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.CANADA);
DecimalFormat format1 = new DecimalFormat("'$'1000.0000", dfs);
DecimalFormat format2 = new DecimalFormat();
format2.applyPattern("'$'1000.0000");
format2.setDecimalFormatSymbols(dfs);
assertTrue("Constructed format did not match applied format object", format2.equals(format1));
assertTrue("Constructed format did not match applied format object", !format1.equals(new DecimalFormat("'$'1000.0000", new DecimalFormatSymbols(Locale.CHINA))));
// case 2: Try to construct object using null arguments.
try {
new DecimalFormat("'$'1000.0000", (DecimalFormatSymbols) null);
fail();
} catch (NullPointerException expected) {
}
try {
new DecimalFormat(null, new DecimalFormatSymbols());
fail();
} catch (NullPointerException expected) {
}
try {
new DecimalFormat(null, (DecimalFormatSymbols) null);
fail();
} catch (NullPointerException expected) {
}
// case 3: Try to construct object using incorrect pattern.
try {
new DecimalFormat("$'", new DecimalFormatSymbols());
fail();
} catch (IllegalArgumentException expected) {
}
}
Aggregations