use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method expect.
// Format test
public void expect(NumberFormat fmt, Number n, String exp, boolean rt) {
StringBuffer saw = new StringBuffer();
FieldPosition pos = new FieldPosition(0);
fmt.format(n, saw, pos);
String pat = ((DecimalFormat) fmt).toPattern();
if (saw.toString().equals(exp)) {
logln("Ok " + n + " x " + pat + " = \"" + saw + "\"");
// => string => number2, might have number2 != number):
if (rt) {
try {
Number n2 = fmt.parse(exp);
StringBuffer saw2 = new StringBuffer();
fmt.format(n2, saw2, pos);
if (!saw2.toString().equals(exp)) {
errln("expect() format test rt, locale " + fmt.getLocale(ULocale.VALID_LOCALE) + ", FAIL \"" + exp + "\" => " + n2 + " => \"" + saw2 + '"');
}
} catch (ParseException e) {
errln("expect() format test rt, locale " + fmt.getLocale(ULocale.VALID_LOCALE) + ", " + e.getMessage());
return;
}
}
} else {
errln("expect() format test, locale " + fmt.getLocale(ULocale.VALID_LOCALE) + ", FAIL " + n + " x " + pat + " = \"" + saw + "\", expected \"" + exp + "\"");
}
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestStringSymbols.
@Test
public void TestStringSymbols() {
DecimalFormatSymbols symbols = new DecimalFormatSymbols(ULocale.US);
String[] customDigits = { "(0)", "(1)", "(2)", "(3)", "(4)", "(5)", "(6)", "(7)", "(8)", "(9)" };
symbols.setDigitStrings(customDigits);
symbols.setDecimalSeparatorString("~~");
symbols.setGroupingSeparatorString("^^");
DecimalFormat fmt = new DecimalFormat("#,##0.0#", symbols);
expect2(fmt, 1234567.89, "(1)^^(2)(3)(4)^^(5)(6)(7)~~(8)(9)");
}
use of android.icu.text.DecimalFormat in project android_packages_apps_Settings by LineageOS.
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.DecimalFormat in project android_packages_apps_Settings by omnirom.
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.DecimalFormat in project android_packages_apps_Settings by crdroidandroid.
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;
}
Aggregations