use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4243108.
/**
* 4243108: format(0.0) gives "0.1" if preceded by parse("99.99")
*/
@Test
public void Test4243108() {
DecimalFormat f = new DecimalFormat("#.#");
String result = f.format(0.0);
if (result.equals("0")) {
logln("OK: got " + result);
} else {
errln("FAIL: got " + result);
}
try {
double dResult = f.parse("99.99").doubleValue();
if (dResult == 99.99) {
logln("OK: got " + dResult);
} else {
errln("FAIL: got " + dResult);
}
} catch (ParseException e) {
errln("Caught a ParseException:");
e.printStackTrace();
}
result = f.format(0.0);
if (result.equals("0")) {
logln("OK: got " + result);
} else {
errln("FAIL: got " + result);
}
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4087244.
/**
* NumberFormat.getCurrencyInstance() produces format that uses
* decimal separator instead of monetary decimal separator.
*
* Rewrote this test not to depend on the actual pattern. Pattern should
* never contain the monetary separator! Decimal separator in pattern is
* interpreted as monetary separator if currency symbol is seen!
*/
@Test
public void Test4087244() {
Locale de = new Locale("pt", "PT");
DecimalFormat df = (DecimalFormat) NumberFormat.getCurrencyInstance(de);
DecimalFormatSymbols sym = df.getDecimalFormatSymbols();
sym.setMonetaryDecimalSeparator('$');
df.setDecimalFormatSymbols(sym);
char decSep = sym.getDecimalSeparator();
char monSep = sym.getMonetaryDecimalSeparator();
// char zero = sym.getZeroDigit(); //The variable is never used
if (decSep == monSep) {
errln("ERROR in test: want decimal sep != monetary sep");
} else {
df.setMinimumIntegerDigits(1);
df.setMinimumFractionDigits(2);
String str = df.format(1.23);
String monStr = "1" + monSep + "23";
String decStr = "1" + decSep + "23";
if (str.indexOf(monStr) >= 0 && str.indexOf(decStr) < 0) {
logln("OK: 1.23 -> \"" + str + "\" contains \"" + monStr + "\" and not \"" + decStr + '"');
} else {
errln("FAIL: 1.23 -> \"" + str + "\", should contain \"" + monStr + "\" and not \"" + decStr + '"');
}
}
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4062486.
/**
* API tests for API addition request A23. FieldPosition.getBeginIndex and
* FieldPosition.getEndIndex.
*/
@Test
public void Test4062486() {
DecimalFormat fmt = new DecimalFormat("#,##0.00");
StringBuffer formatted = new StringBuffer();
FieldPosition field = new FieldPosition(0);
Double num = new Double(1234.5);
fmt.format(num, formatted, field);
if (field.getBeginIndex() != 0 && field.getEndIndex() != 5)
errln("Format 1234.5 failed. Begin index: " + field.getBeginIndex() + " End index: " + field.getEndIndex());
field.setBeginIndex(7);
field.setEndIndex(4);
if (field.getBeginIndex() != 7 && field.getEndIndex() != 4)
errln("Set begin/end field indexes failed. Begin index: " + field.getBeginIndex() + " End index: " + field.getEndIndex());
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4068693.
/**
* DecimalFormat.parse returns wrong value
*/
@Test
public void Test4068693() {
logln("----- Test Application -----");
// ParsePosition pos;
DecimalFormat df = new DecimalFormat();
Number d = df.parse("123.55456", new ParsePosition(0));
if (!d.toString().equals("123.55456")) {
errln("Result -> " + d.doubleValue());
}
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4147295.
/**
* DecimalFormat.applyPattern() sets minimum integer digits incorrectly.
* CANNOT REPRODUCE
* This bug is a duplicate of 4139344, which is a duplicate of 4134300
*/
@Test
public void Test4147295() {
DecimalFormat sdf = new DecimalFormat();
String pattern = "#,###";
logln("Applying pattern \"" + pattern + "\"");
sdf.applyPattern(pattern);
int minIntDig = sdf.getMinimumIntegerDigits();
if (minIntDig != 0) {
errln("Test failed");
errln(" Minimum integer digits : " + minIntDig);
errln(" new pattern: " + sdf.toPattern());
} else {
logln("Test passed");
logln(" Minimum integer digits : " + minIntDig);
}
}
Aggregations