use of android.icu.text.NumberFormat in project j2objc by google.
the class PluralRulesTest method TestBasicFraction.
@Test
public void TestBasicFraction() {
String[][] tests = { { "en", "one: j is 1" }, { "1", "0", "1", "one" }, { "1", "2", "1.00", "other" } };
ULocale locale = null;
NumberFormat nf = null;
PluralRules pr = null;
for (String[] row : tests) {
switch(row.length) {
case 2:
locale = ULocale.forLanguageTag(row[0]);
nf = NumberFormat.getInstance(locale);
pr = PluralRules.createRules(row[1]);
break;
case 4:
double n = Double.parseDouble(row[0]);
int minFracDigits = Integer.parseInt(row[1]);
nf.setMinimumFractionDigits(minFracDigits);
String expectedFormat = row[2];
String expectedKeyword = row[3];
UFieldPosition pos = new UFieldPosition();
String formatted = nf.format(1.0, new StringBuffer(), pos).toString();
int countVisibleFractionDigits = pos.getCountVisibleFractionDigits();
long fractionDigits = pos.getFractionDigits();
String keyword = pr.select(n, countVisibleFractionDigits, fractionDigits);
assertEquals("Formatted " + n + "\t" + minFracDigits, expectedFormat, formatted);
assertEquals("Keyword " + n + "\t" + minFracDigits, expectedKeyword, keyword);
break;
default:
throw new RuntimeException();
}
}
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class MyNumberFormat method test4233840.
/**
* 4233840: NumberFormat does not round correctly
*/
@Test
public void test4233840() {
float f = 0.0099f;
NumberFormat nf = new DecimalFormat("0.##", new DecimalFormatSymbols(Locale.US));
nf.setMinimumFractionDigits(2);
String result = nf.format(f);
if (!result.equals("0.01")) {
errln("FAIL: input: " + f + ", expected: 0.01, got: " + result);
}
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class MyNumberFormat method assignFloatValue.
public float assignFloatValue(float returnfloat) {
logln(" VALUE " + returnfloat);
NumberFormat nfcommon = NumberFormat.getCurrencyInstance(Locale.US);
nfcommon.setGroupingUsed(false);
String stringValue = nfcommon.format(returnfloat).substring(1);
if (Float.valueOf(stringValue).floatValue() != returnfloat)
errln(" DISPLAYVALUE " + stringValue);
return returnfloat;
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class MyNumberFormat method Test4114639.
/**
* NumberFormat.parse doesn't return null
*/
@Test
public void Test4114639() {
NumberFormat format = NumberFormat.getInstance();
String text = "time 10:x";
ParsePosition pos = new ParsePosition(8);
Number result = format.parse(text, pos);
// Should be null; it isn't
if (result != null)
errln("Should return null but got : " + result);
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class MyNumberFormat method Test4098741.
/**
* Tests the setMaximumFractionDigits limit.
*/
@Test
public void Test4098741() {
try {
NumberFormat fmt = NumberFormat.getPercentInstance();
fmt.setMaximumFractionDigits(20);
logln(fmt.format(.001));
} catch (Exception foo) {
warnln("Bug 4098471 failed with exception thrown : " + foo.getMessage());
}
}
Aggregations