use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4125885.
/**
* DecimalFormat.format() delivers wrong string.
*/
@Test
public void Test4125885() {
double rate = 12.34;
DecimalFormat formatDec = new DecimalFormat("000.00");
logln("toPattern: " + formatDec.toPattern());
String rateString = formatDec.format(rate);
if (!rateString.equals("012.34"))
errln("result : " + rateString + " expected : 012.34");
rate = 0.1234;
formatDec = null;
formatDec = new DecimalFormat("+000.00%;-000.00%");
logln("toPattern: " + formatDec.toPattern());
rateString = formatDec.format(rate);
if (!rateString.equals("+012.34%"))
errln("result : " + rateString + " expected : +012.34%");
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4106658.
/**
* DecimalFormat.format() incorrectly formats negative doubles.
*/
@Test
public void Test4106658() {
Locale savedLocale = Locale.getDefault();
Locale.setDefault(Locale.US);
// Corrected; see 4147706
DecimalFormat df = new DecimalFormat();
double d1 = -0.0;
double d2 = -0.0001;
StringBuffer buffer = new StringBuffer();
logln("pattern: \"" + df.toPattern() + "\"");
df.format(d1, buffer, new FieldPosition(0));
if (!buffer.toString().equals("-0")) {
// Corrected; see 4147706
errln(d1 + " is formatted as " + buffer);
}
buffer.setLength(0);
df.format(d2, buffer, new FieldPosition(0));
if (!buffer.toString().equals("-0")) {
// Corrected; see 4147706
errln(d2 + " is formatted as " + buffer);
}
Locale.setDefault(savedLocale);
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4093610.
/* bug 4071859
* Test rounding for nearest even.
*/
@Test
public void Test4093610() {
DecimalFormat df = new DecimalFormat("#0.#");
roundingTest(df, 12.35, "12.4");
roundingTest(df, 12.45, "12.4");
roundingTest(df, 12.452, "12.5");
roundingTest(df, 12.55, "12.6");
roundingTest(df, 12.65, "12.6");
roundingTest(df, 12.652, "12.7");
roundingTest(df, 12.75, "12.8");
roundingTest(df, 12.752, "12.8");
roundingTest(df, 12.85, "12.8");
roundingTest(df, 12.852, "12.9");
roundingTest(df, 12.95, "13");
roundingTest(df, 12.952, "13");
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatRegressionTest method TestJB5509.
/*
* Test case for JB#5509, strict parsing issue
*/
@Test
public void TestJB5509() {
String[] data = { "1,2", "1.2", "1,2.5", "1,23.5", "1,234.5", "1,234", "1,234,567", "1,234,567.8", "1,234,5", "1,234,5.6", "1,234,56.7" };
boolean[] expected = { // false for expected parse failure
false, true, false, false, true, true, true, true, false, false, false, false };
DecimalFormat df = new DecimalFormat("#,##0.###", new DecimalFormatSymbols(new ULocale("en_US")));
df.setParseStrict(true);
for (int i = 0; i < data.length; i++) {
try {
df.parse(data[i]);
if (!expected[i]) {
errln("Failed: ParseException must be thrown for string " + data[i]);
}
} catch (ParseException pe) {
if (expected[i]) {
errln("Failed: ParseException must not be thrown for string " + data[i]);
}
}
}
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatRegressionTest method TestNBSPInPattern.
@Test
public void TestNBSPInPattern() {
NumberFormat nf = null;
String testcase;
testcase = "ar_AE UNUM_CURRENCY";
nf = NumberFormat.getCurrencyInstance(new ULocale("ar_AE"));
checkNBSPPatternRT(testcase, nf);
// if we don't have CLDR 1.6 data, bring out the problem anyways
String SPECIAL_PATTERN = "\u00A4\u00A4'\u062f.\u0625.\u200f\u00a0'###0.00";
testcase = "ar_AE special pattern: " + SPECIAL_PATTERN;
nf = new DecimalFormat();
((DecimalFormat) nf).applyPattern(SPECIAL_PATTERN);
checkNBSPPatternRT(testcase, nf);
}
Aggregations