use of android.icu.text.NumberFormat in project j2objc by google.
the class MyNumberFormat method Test4071014.
/**
* Data rounding errors for German (Germany) locale
*/
@Test
public void Test4071014() {
NumberFormat formatter;
String tempString;
/* user error :
String expectedDefault = "-5.789,987";
String expectedCurrency = "5.789,98\u00a0DM";
String expectedPercent = "-578.998%";
*/
String expectedDefault = "-5.789,988";
String expectedCurrency = "5.789,99\u00a0" + EURO;
String expectedPercent = "-578.999\u00a0%";
formatter = NumberFormat.getNumberInstance(Locale.GERMANY);
tempString = formatter.format(-5789.9876);
if (tempString.equals(expectedDefault)) {
logln("Bug 4071014 default test passed.");
} else {
errln("Failed:" + " Expected " + expectedDefault + " Received " + tempString);
}
formatter = NumberFormat.getCurrencyInstance(Locale.GERMANY);
tempString = formatter.format(5789.9876);
if (tempString.equals(expectedCurrency)) {
logln("Bug 4071014 currency test passed.");
} else {
errln("Failed:" + " Expected " + expectedCurrency + " Received " + tempString);
}
formatter = NumberFormat.getPercentInstance(Locale.GERMANY);
tempString = formatter.format(-5789.9876);
if (tempString.equals(expectedPercent)) {
logln("Bug 4071014 percentage test passed.");
} else {
errln("Failed:" + " Expected " + expectedPercent + " Received " + tempString);
}
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class MyNumberFormat method Test4162852.
/**
* NumberFormat does not parse negative zero.
*/
@Test
public void Test4162852() throws ParseException {
for (int i = 0; i < 2; ++i) {
NumberFormat f = (i == 0) ? NumberFormat.getInstance() : NumberFormat.getPercentInstance();
double d = -0.0;
String s = f.format(d);
double e = f.parse(s).doubleValue();
logln("" + d + " -> " + '"' + s + '"' + " -> " + e);
if (e != 0.0 || 1.0 / e > 0.0) {
logln("Failed to parse negative zero");
}
}
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class MyNumberFormat method Test4070798.
/**
* Number format data rounding errors for locale FR
*/
@Test
public void Test4070798() {
NumberFormat formatter;
String tempString;
/* User error :
String expectedDefault = "-5\u00a0789,987";
String expectedCurrency = "5\u00a0789,98\u00a0F";
String expectedPercent = "-578\u00a0998%";
*/
String expectedDefault = "-5\u00a0789,988";
// euro
String expectedCurrency = "5\u00a0789,99\u00a0" + EURO;
String expectedPercent = "-578\u00a0999\u00a0%";
formatter = NumberFormat.getNumberInstance(Locale.FRANCE);
tempString = formatter.format(-5789.9876);
if (tempString.equals(expectedDefault)) {
logln("Bug 4070798 default test passed.");
} else {
errln("Failed:" + " Expected " + expectedDefault + " Received " + tempString);
}
formatter = NumberFormat.getCurrencyInstance(Locale.FRANCE);
tempString = formatter.format(5789.9876);
if (tempString.equals(expectedCurrency)) {
logln("Bug 4070798 currency test assed.");
} else {
errln("Failed:" + " Expected " + expectedCurrency + " Received " + tempString);
}
formatter = NumberFormat.getPercentInstance(Locale.FRANCE);
tempString = formatter.format(-5789.9876);
if (tempString.equals(expectedPercent)) {
logln("Bug 4070798 percentage test passed.");
} else {
errln("Failed:" + " Expected " + expectedPercent + " Received " + tempString);
}
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class MyNumberFormat method Test4217661.
/**
* DecimalFormat formats 1.001 to "1.00" instead of "1" with 2 fraction
* digits.
*/
@Test
public void Test4217661() {
Object[] DATA = { new Double(0.001), "0", new Double(1.001), "1", new Double(0.006), "0.01", new Double(1.006), "1.01" };
NumberFormat fmt = NumberFormat.getInstance(Locale.US);
fmt.setMaximumFractionDigits(2);
for (int i = 0; i < DATA.length; i += 2) {
String s = fmt.format(((Double) DATA[i]).doubleValue());
if (!s.equals(DATA[i + 1])) {
errln("FAIL: Got " + s + ", exp " + DATA[i + 1]);
}
}
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class NumberFormatRegressionTest method TestSerialization.
// Test New serialized DecimalFormat(2.0) read old serialized forms of DecimalFormat(1.3.1.1)
@Test
public void TestSerialization() throws IOException {
byte[][] contents = NumberFormatSerialTestData.getContent();
double data = 1234.56;
String[] expected = { "1,234.56", "$1,234.56", "123,456%", "1.23456E3" };
for (int i = 0; i < 4; ++i) {
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(contents[i]));
try {
NumberFormat format = (NumberFormat) ois.readObject();
String result = format.format(data);
if (result.equals(expected[i])) {
logln("OK: Deserialized bogus NumberFormat(new version read old version)");
} else {
errln("FAIL: the test data formats are not euqal");
}
} catch (Exception e) {
warnln("FAIL: " + e.getMessage());
}
}
}
Aggregations