Search in sources :

Example 61 with NumberFormat

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);
}
Also used : ULocale(android.icu.util.ULocale) Locale(java.util.Locale) RelativeDateTimeFormatter(android.icu.text.RelativeDateTimeFormatter) NumberFormat(android.icu.text.NumberFormat) Test(org.junit.Test)

Example 62 with NumberFormat

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);
}
Also used : Locale(java.util.Locale) NumberFormat(android.icu.text.NumberFormat)

Example 63 with NumberFormat

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;
}
Also used : DecimalFormat(android.icu.text.DecimalFormat) NumberFormat(android.icu.text.NumberFormat)

Example 64 with NumberFormat

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;
}
Also used : DecimalFormat(android.icu.text.DecimalFormat) NumberFormat(android.icu.text.NumberFormat)

Example 65 with NumberFormat

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;
}
Also used : DecimalFormat(android.icu.text.DecimalFormat) NumberFormat(android.icu.text.NumberFormat)

Aggregations

NumberFormat (android.icu.text.NumberFormat)105 Test (org.junit.Test)84 ULocale (android.icu.util.ULocale)39 RuleBasedNumberFormat (android.icu.text.RuleBasedNumberFormat)35 DecimalFormat (android.icu.text.DecimalFormat)27 Locale (java.util.Locale)24 ParseException (java.text.ParseException)20 ParsePosition (java.text.ParsePosition)13 DecimalFormatSymbols (android.icu.text.DecimalFormatSymbols)12 CompactDecimalFormat (android.icu.text.CompactDecimalFormat)11 FieldPosition (java.text.FieldPosition)9 IOException (java.io.IOException)7 DateFormat (android.icu.text.DateFormat)5 Calendar (android.icu.util.Calendar)5 Date (java.util.Date)5 BigDecimal (android.icu.math.BigDecimal)4 DisplayContext (android.icu.text.DisplayContext)4 MeasureFormat (android.icu.text.MeasureFormat)4 SimpleDateFormat (android.icu.text.SimpleDateFormat)4 PluralFormat (android.icu.text.PluralFormat)3