use of android.icu.text.NumberFormat in project platform_packages_apps_Settings by BlissRoms.
the class FileSizeFormatter method getNumberFormatter.
private static NumberFormat getNumberFormatter(Locale locale, int fractionDigits) {
final NumberFormat numberFormatter = NumberFormat.getInstance(locale);
numberFormatter.setMinimumFractionDigits(fractionDigits);
numberFormatter.setMaximumFractionDigits(fractionDigits);
numberFormatter.setGroupingUsed(false);
if (numberFormatter instanceof DecimalFormat) {
// We do this only for DecimalFormat, since in the general NumberFormat case, calling
// setRoundingMode may throw an exception.
numberFormatter.setRoundingMode(BigDecimal.ROUND_HALF_UP);
}
return numberFormatter;
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class BigNumberFormatTest method expect.
private void expect(Object fmto, Object numo, Object expo) {
NumberFormat fmt = null, fmts[] = null;
Number num = null, nums[] = null;
String exp = null, exps[] = null;
if (fmto instanceof NumberFormat[]) {
fmts = (NumberFormat[]) fmto;
} else {
fmt = (NumberFormat) fmto;
}
if (numo instanceof Number[]) {
nums = (Number[]) numo;
} else {
num = (Number) numo;
}
if (expo instanceof String[]) {
exps = (String[]) expo;
} else {
exp = (String) expo;
}
int n = 1;
if (fmts != null) {
n = Math.max(n, fmts.length);
}
if (nums != null) {
n = Math.max(n, nums.length);
}
if (exps != null) {
n = Math.max(n, exps.length);
}
for (int i = 0; i < n; ++i) {
expect(fmts == null ? fmt : fmts[i], nums == null ? num : nums[i], exps == null ? exp : exps[i]);
}
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class BigNumberFormatTest method Test4161100.
@Test
public void Test4161100() {
NumberFormat f = NumberFormat.getInstance();
f.setMinimumFractionDigits(1);
f.setMaximumFractionDigits(1);
double a = -0.09;
String s = f.format(a);
logln(a + " x " + ((DecimalFormat) f).toPattern() + " = " + s);
if (!s.equals("-0.1")) {
errln("FAIL");
}
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class BigNumberFormatTest method TestBigDecimalJ28.
@Test
public void TestBigDecimalJ28() {
String[] DATA = { "1", "1E0", "-1", "-1E0", "0", "0E0", "12e34", "1.2E35", "-12.3e-45", "-1.23E-44", "0.73e-7", "7.3E-8" };
NumberFormat fmt = NumberFormat.getScientificInstance(Locale.US);
logln("Pattern: " + ((DecimalFormat) fmt).toPattern());
for (int i = 0; i < DATA.length; i += 2) {
String input = DATA[i];
String exp = DATA[i + 1];
android.icu.math.BigDecimal bd = new android.icu.math.BigDecimal(input);
String output = fmt.format(bd);
if (output.equals(exp)) {
logln("input=" + input + " num=" + bd + " output=" + output);
} else {
errln("FAIL: input=" + input + " num=" + bd + " output=" + output + " expected=" + exp);
}
}
}
use of android.icu.text.NumberFormat in project j2objc by google.
the class CompactDecimalFormatTest method TestArabicLongStyle.
@Test
public void TestArabicLongStyle() {
NumberFormat cdf = CompactDecimalFormat.getInstance(new Locale("ar"), CompactStyle.LONG);
assertEquals("Arabic Long", "\u061C-\u0665\u066B\u0663 \u0623\u0644\u0641", cdf.format(-5300));
}
Aggregations