use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestMissingFieldPositionsPerCentPattern.
@Test
public void TestMissingFieldPositionsPerCentPattern() {
// Check PERCENT with more digits
DecimalFormatSymbols us_symbols = new DecimalFormatSymbols(ULocale.US);
DecimalFormat fmtPercent = new DecimalFormat("0.#####%", us_symbols);
Number number = new Double(-0.986);
String numFmtted = fmtPercent.format(number);
checkFormatWithField("sign", fmtPercent, number, numFmtted, NumberFormat.Field.SIGN, 0, 1);
checkFormatWithField("integer", fmtPercent, number, numFmtted, NumberFormat.Field.INTEGER, 1, 3);
checkFormatWithField("decimal separator", fmtPercent, number, numFmtted, NumberFormat.Field.DECIMAL_SEPARATOR, 3, 4);
checkFormatWithField("fraction", fmtPercent, number, numFmtted, NumberFormat.Field.FRACTION, 4, 5);
checkFormatWithField("percent", fmtPercent, number, numFmtted, NumberFormat.Field.PERCENT, 5, 6);
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestParseRequiredDecimalPoint.
@Test
public void TestParseRequiredDecimalPoint() {
String[] testPattern = { "00.####", "00.0", "00" };
String value2Parse = "99";
double parseValue = 99;
DecimalFormat parser = new DecimalFormat();
double result;
boolean hasDecimalPoint;
for (int i = 0; i < testPattern.length; i++) {
parser.applyPattern(testPattern[i]);
hasDecimalPoint = testPattern[i].contains(".");
parser.setDecimalPatternMatchRequired(false);
try {
result = parser.parse(value2Parse).doubleValue();
assertEquals("wrong parsed value", parseValue, result);
} catch (ParseException e) {
TestFmwk.errln("Parsing " + value2Parse + " should have succeeded with " + testPattern[i] + " and isDecimalPointMatchRequired set to: " + parser.isDecimalPatternMatchRequired());
}
parser.setDecimalPatternMatchRequired(true);
try {
result = parser.parse(value2Parse).doubleValue();
if (hasDecimalPoint) {
TestFmwk.errln("Parsing " + value2Parse + " should NOT have succeeded with " + testPattern[i] + " and isDecimalPointMatchRequired set to: " + parser.isDecimalPatternMatchRequired());
}
} catch (ParseException e) {
// OK, should fail
}
}
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestCustomCurrencySignAndSeparator.
@Test
public void TestCustomCurrencySignAndSeparator() {
DecimalFormatSymbols custom = new DecimalFormatSymbols(ULocale.US);
custom.setCurrencySymbol("*");
custom.setMonetaryGroupingSeparator('^');
custom.setMonetaryDecimalSeparator(':');
DecimalFormat fmt = new DecimalFormat("\u00A4 #,##0.00", custom);
final String numstr = "* 1^234:56";
expect2(fmt, 1234.56, numstr);
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestScientificGrouping.
@Test
public void TestScientificGrouping() {
// jb 2552
DecimalFormat fmt = new DecimalFormat("###.##E0");
expect(fmt, .01234, "12.3E-3");
expect(fmt, .1234, "123E-3");
expect(fmt, 1.234, "1.23E0");
expect(fmt, 12.34, "12.3E0");
expect(fmt, 123.4, "123E0");
expect(fmt, 1234, "1.23E3");
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestPatterns2.
/**
* Upgrade to alphaWorks
*/
@Test
public void TestPatterns2() {
DecimalFormatSymbols US = new DecimalFormatSymbols(Locale.US);
DecimalFormat fmt = new DecimalFormat("#", US);
char hat = 0x005E;
/*^*/
expectPad(fmt, "*^#", DecimalFormat.PAD_BEFORE_PREFIX, 1, hat);
expectPad(fmt, "$*^#", DecimalFormat.PAD_AFTER_PREFIX, 2, hat);
expectPad(fmt, "#*^", DecimalFormat.PAD_BEFORE_SUFFIX, 1, hat);
expectPad(fmt, "#$*^", DecimalFormat.PAD_AFTER_SUFFIX, 2, hat);
expectPad(fmt, "$*^$#", -1);
expectPad(fmt, "#$*^$", -1);
expectPad(fmt, "'pre'#,##0*x'post'", DecimalFormat.PAD_BEFORE_SUFFIX, 12, (char) 0x0078);
expectPad(fmt, "''#0*x", DecimalFormat.PAD_BEFORE_SUFFIX, 3, (char) 0x0078);
expectPad(fmt, "'I''ll'*a###.##", DecimalFormat.PAD_AFTER_PREFIX, 10, (char) 0x0061);
fmt.applyPattern("AA#,##0.00ZZ");
fmt.setPadCharacter(hat);
fmt.setFormatWidth(10);
fmt.setPadPosition(DecimalFormat.PAD_BEFORE_PREFIX);
expectPat(fmt, "*^AA#,##0.00ZZ");
fmt.setPadPosition(DecimalFormat.PAD_BEFORE_SUFFIX);
expectPat(fmt, "AA#,##0.00*^ZZ");
fmt.setPadPosition(DecimalFormat.PAD_AFTER_SUFFIX);
expectPat(fmt, "AA#,##0.00ZZ*^");
// 12 3456789012
String exp = "AA*^#,##0.00ZZ";
fmt.setFormatWidth(12);
fmt.setPadPosition(DecimalFormat.PAD_AFTER_PREFIX);
expectPat(fmt, exp);
fmt.setFormatWidth(13);
// 12 34567890123
expectPat(fmt, "AA*^##,##0.00ZZ");
fmt.setFormatWidth(14);
// 12 345678901234
expectPat(fmt, "AA*^###,##0.00ZZ");
fmt.setFormatWidth(15);
// 12 3456789012345
// This is the interesting case
expectPat(fmt, "AA*^####,##0.00ZZ");
fmt.setFormatWidth(16);
// 12 34567890123456
expectPat(fmt, "AA*^#,###,##0.00ZZ");
}
Aggregations