use of android.icu.text.NumberFormat in project j2objc by google.
the class RelativeDateTimeFormatterTest method TestJavaLocale.
@Test
public void TestJavaLocale() {
Locale loc = Locale.US;
double amount = 12.3456d;
RelativeDateTimeFormatter fmt = RelativeDateTimeFormatter.getInstance(loc);
String s = fmt.format(amount, Direction.LAST, RelativeUnit.SECONDS);
assertEquals("Java Locale.US", "12.346 seconds ago", s);
// Modified instance
NumberFormat nf = fmt.getNumberFormat();
nf.setMaximumFractionDigits(1);
fmt = RelativeDateTimeFormatter.getInstance(loc, nf);
s = fmt.format(amount, Direction.LAST, RelativeUnit.SECONDS);
assertEquals("Java Locale.US", "12.3 seconds ago", s);
}
use of android.icu.text.NumberFormat in project android_packages_apps_Settings by LineageOS.
the class FileSizeFormatter method formatRoundedBytesResult.
private static String formatRoundedBytesResult(@NonNull Context context, @NonNull RoundedBytesResult input) {
final Locale locale = localeFromContext(context);
final NumberFormat numberFormatter = getNumberFormatter(locale, input.fractionDigits);
return formatMeasureShort(locale, numberFormatter, input.value, input.units);
}
use of android.icu.text.NumberFormat 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.NumberFormat 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.NumberFormat 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