use of java.text.DecimalFormatSymbols in project j2objc by google.
the class DecimalFormatTest method test_parse_minusInfinityBigDecimalFalse.
public void test_parse_minusInfinityBigDecimalFalse() {
// Regression test for HARMONY-106
DecimalFormat format = (DecimalFormat) NumberFormat.getInstance();
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
Number number = format.parse("-" + symbols.getInfinity(), new ParsePosition(0));
assertTrue(number instanceof Double);
assertTrue(Double.isInfinite(number.doubleValue()));
}
use of java.text.DecimalFormatSymbols in project j2objc by google.
the class DecimalFormatTest method test_formatDouble_maximumFractionDigits.
public void test_formatDouble_maximumFractionDigits() {
DecimalFormat df = new DecimalFormat("###0.##", new DecimalFormatSymbols(Locale.US));
df.setMaximumFractionDigits(3);
assertEquals(3, df.getMaximumFractionDigits());
assertEquals("1.235", df.format(1.23456));
df.setMinimumFractionDigits(4);
assertEquals(4, df.getMaximumFractionDigits());
assertEquals("456.0000", df.format(456));
df = new DecimalFormat("##0.#");
df.setMaximumFractionDigits(30);
assertEquals("0", df.format(0.0));
assertEquals("-0", df.format(-0.0));
assertEquals("1", df.format(1.0));
assertEquals("-1", df.format(-1.0));
}
use of java.text.DecimalFormatSymbols 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.DecimalFormatSymbols 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);
}
use of java.text.DecimalFormatSymbols 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));
}
Aggregations