use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestRoundUnnecessarytIssue11808.
// Testing for Issue 11808.
@Test
public void TestRoundUnnecessarytIssue11808() {
DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance();
StringBuffer result = new StringBuffer("");
df.setRoundingMode(BigDecimal.ROUND_UNNECESSARY);
df.applyPattern("00.0#E0");
try {
df.format(99999.0, result, new FieldPosition(0));
fail("Missing ArithmeticException for double: " + result);
} catch (ArithmeticException expected) {
// The exception should be thrown, since rounding is needed.
}
try {
result = df.format(99999, result, new FieldPosition(0));
fail("Missing ArithmeticException for int: " + result);
} catch (ArithmeticException expected) {
// The exception should be thrown, since rounding is needed.
}
try {
result = df.format(new BigInteger("999999"), result, new FieldPosition(0));
fail("Missing ArithmeticException for BigInteger: " + result);
} catch (ArithmeticException expected) {
// The exception should be thrown, since rounding is needed.
}
try {
result = df.format(new BigDecimal("99999"), result, new FieldPosition(0));
fail("Missing ArithmeticException for BigDecimal: " + result);
} catch (ArithmeticException expected) {
// The exception should be thrown, since rounding is needed.
}
try {
result = df.format(new BigDecimal("-99999"), result, new FieldPosition(0));
fail("Missing ArithmeticException for BigDecimal: " + result);
} catch (ArithmeticException expected) {
// The exception should be thrown, since rounding is needed.
}
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestMissingFieldPositionsPositiveBigDec.
@Test
public void TestMissingFieldPositionsPositiveBigDec() {
// Check complex positive;negative pattern.
DecimalFormatSymbols us_symbols = new DecimalFormatSymbols(ULocale.US);
DecimalFormat fmtPosNegSign = new DecimalFormat("+0.####E+00;-0.#######E+0", us_symbols);
Number positiveExp = new Double("9876543210");
String posExpFormatted = fmtPosNegSign.format(positiveExp);
checkFormatWithField("sign", fmtPosNegSign, positiveExp, posExpFormatted, NumberFormat.Field.SIGN, 0, 1);
checkFormatWithField("integer", fmtPosNegSign, positiveExp, posExpFormatted, NumberFormat.Field.INTEGER, 1, 2);
checkFormatWithField("decimal separator", fmtPosNegSign, positiveExp, posExpFormatted, NumberFormat.Field.DECIMAL_SEPARATOR, 2, 3);
checkFormatWithField("fraction", fmtPosNegSign, positiveExp, posExpFormatted, NumberFormat.Field.FRACTION, 3, 7);
checkFormatWithField("exponent symbol", fmtPosNegSign, positiveExp, posExpFormatted, NumberFormat.Field.EXPONENT_SYMBOL, 7, 8);
checkFormatWithField("exponent sign", fmtPosNegSign, positiveExp, posExpFormatted, NumberFormat.Field.EXPONENT_SIGN, 8, 9);
checkFormatWithField("exponent", fmtPosNegSign, positiveExp, posExpFormatted, NumberFormat.Field.EXPONENT, 9, 11);
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4134034.
/**
**
* DecimalFormat produces extra zeros when formatting numbers.
*/
@Test
public void Test4134034() {
DecimalFormat nf = new DecimalFormat("##,###,###.00");
String f = nf.format(9.02);
if (f.equals("9.02"))
logln(f + " ok");
else
errln("9.02 -> " + f + "; want 9.02");
f = nf.format(0);
if (f.equals(".00"))
logln(f + " ok");
else
errln("0 -> " + f + "; want .00");
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4092480.
/**
* DecimalFormat: Negative format ignored.
*/
@Test
public void Test4092480() {
DecimalFormat dfFoo = new DecimalFormat("000");
try {
dfFoo.applyPattern("0000;-000");
if (!dfFoo.toPattern().equals("#0000"))
errln("dfFoo.toPattern : " + dfFoo.toPattern());
logln(dfFoo.format(42));
logln(dfFoo.format(-42));
dfFoo.applyPattern("000;-000");
if (!dfFoo.toPattern().equals("#000"))
errln("dfFoo.toPattern : " + dfFoo.toPattern());
logln(dfFoo.format(42));
logln(dfFoo.format(-42));
dfFoo.applyPattern("000;-0000");
if (!dfFoo.toPattern().equals("#000"))
errln("dfFoo.toPattern : " + dfFoo.toPattern());
logln(dfFoo.format(42));
logln(dfFoo.format(-42));
dfFoo.applyPattern("0000;-000");
if (!dfFoo.toPattern().equals("#0000"))
errln("dfFoo.toPattern : " + dfFoo.toPattern());
logln(dfFoo.format(42));
logln(dfFoo.format(-42));
} catch (Exception foo) {
errln("Message " + foo.getMessage());
}
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4087251.
/**
* DecimalFormat.applyPattern(String) allows illegal patterns
*/
@Test
public void Test4087251() {
DecimalFormat df = new DecimalFormat();
try {
df.applyPattern("#.#.#");
logln("toPattern() returns \"" + df.toPattern() + "\"");
errln("applyPattern(\"#.#.#\") doesn't throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
logln("Caught Illegal Argument Error !");
}
// Second test; added 5/11/98 when reported to fail on 1.2b3
try {
df.applyPattern("#0.0#0#0");
logln("toPattern() returns \"" + df.toPattern() + "\"");
errln("applyPattern(\"#0.0#0#0\") doesn't throw IllegalArgumentException");
} catch (IllegalArgumentException e) {
logln("Ok - IllegalArgumentException for #0.0#0#0");
}
}
Aggregations