use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestFieldPositionDecimal.
@Test
public void TestFieldPositionDecimal() {
DecimalFormat nf = (DecimalFormat) android.icu.text.NumberFormat.getInstance(ULocale.ENGLISH);
nf.setPositivePrefix("FOO");
nf.setPositiveSuffix("BA");
StringBuffer buffer = new StringBuffer();
FieldPosition fp = new FieldPosition(NumberFormat.Field.DECIMAL_SEPARATOR);
nf.format(35.47, buffer, fp);
assertEquals("35.47", "FOO35.47BA", buffer.toString());
assertEquals("fp begin", 5, fp.getBeginIndex());
assertEquals("fp end", 6, fp.getEndIndex());
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestMissingFieldPositionsNegativeBigDec.
@Test
public void TestMissingFieldPositionsNegativeBigDec() {
// 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 negativeExp = new BigDecimal("-0.000000987654321083");
String negExpFormatted = fmtPosNegSign.format(negativeExp);
checkFormatWithField("sign", fmtPosNegSign, negativeExp, negExpFormatted, NumberFormat.Field.SIGN, 0, 1);
checkFormatWithField("integer", fmtPosNegSign, negativeExp, negExpFormatted, NumberFormat.Field.INTEGER, 1, 2);
checkFormatWithField("decimal separator", fmtPosNegSign, negativeExp, negExpFormatted, NumberFormat.Field.DECIMAL_SEPARATOR, 2, 3);
checkFormatWithField("fraction", fmtPosNegSign, negativeExp, negExpFormatted, NumberFormat.Field.FRACTION, 3, 7);
checkFormatWithField("exponent symbol", fmtPosNegSign, negativeExp, negExpFormatted, NumberFormat.Field.EXPONENT_SYMBOL, 7, 8);
checkFormatWithField("exponent sign", fmtPosNegSign, negativeExp, negExpFormatted, NumberFormat.Field.EXPONENT_SIGN, 8, 9);
checkFormatWithField("exponent", fmtPosNegSign, negativeExp, negExpFormatted, NumberFormat.Field.EXPONENT, 9, 11);
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestIllegalPatterns.
@Test
public void TestIllegalPatterns() {
// Test cases:
// Prefix with "-:" for illegal patterns
// Prefix with "+:" for legal patterns
String[] DATA = { // Unquoted special characters in the suffix are illegal
"-:000.000|###", "+:000.000'|###'" };
for (int i = 0; i < DATA.length; ++i) {
String pat = DATA[i];
boolean valid = pat.charAt(0) == '+';
pat = pat.substring(2);
Exception e = null;
try {
// locale doesn't matter here
new DecimalFormat(pat);
} catch (IllegalArgumentException e1) {
e = e1;
} catch (IndexOutOfBoundsException e1) {
e = e1;
}
String msg = (e == null) ? "success" : e.getMessage();
if ((e == null) == valid) {
logln("Ok: pattern \"" + pat + "\": " + msg);
} else {
errln("FAIL: pattern \"" + pat + "\" should have " + (valid ? "succeeded" : "failed") + "; got " + msg);
}
}
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestScientific2.
@Test
public void TestScientific2() {
// jb 2552
DecimalFormat fmt = (DecimalFormat) NumberFormat.getCurrencyInstance();
Number num = new Double(12.34);
expect(fmt, num, "$12.34");
fmt.setScientificNotation(true);
expect(fmt, num, "$1.23E1");
fmt.setScientificNotation(false);
expect(fmt, num, "$12.34");
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestSetCurrency.
@Test
public void TestSetCurrency() {
DecimalFormatSymbols decf1 = DecimalFormatSymbols.getInstance(ULocale.US);
DecimalFormatSymbols decf2 = DecimalFormatSymbols.getInstance(ULocale.US);
decf2.setCurrencySymbol("UKD");
DecimalFormat format1 = new DecimalFormat("000.000", decf1);
DecimalFormat format2 = new DecimalFormat("000.000", decf2);
Currency euro = Currency.getInstance("EUR");
format1.setCurrency(euro);
format2.setCurrency(euro);
assertEquals("Reset with currency symbol", format1, format2);
}
Aggregations