Search in sources :

Example 11 with PluralFormat

use of android.icu.text.PluralFormat in project j2objc by google.

the class PluralFormatUnitTest method TestDecimals.

@Test
public void TestDecimals() {
    // Simple number replacement.
    PluralFormat pf = new PluralFormat(ULocale.ENGLISH, "one{one meter}other{# meters}");
    assertEquals("simple format(1)", "one meter", pf.format(1));
    assertEquals("simple format(1.5)", "1.5 meters", pf.format(1.5));
    PluralFormat pf2 = new PluralFormat(ULocale.ENGLISH, "offset:1 one{another meter}other{another # meters}");
    pf2.setNumberFormat(new DecimalFormat("0.0", new DecimalFormatSymbols(ULocale.ENGLISH)));
    assertEquals("offset-decimals format(1)", "another 0.0 meters", pf2.format(1));
    assertEquals("offset-decimals format(2)", "another 1.0 meters", pf2.format(2));
    assertEquals("offset-decimals format(2.5)", "another 1.5 meters", pf2.format(2.5));
}
Also used : DecimalFormatSymbols(android.icu.text.DecimalFormatSymbols) DecimalFormat(android.icu.text.DecimalFormat) PluralFormat(android.icu.text.PluralFormat) Test(org.junit.Test)

Aggregations

PluralFormat (android.icu.text.PluralFormat)11 Test (org.junit.Test)8 NumberFormat (android.icu.text.NumberFormat)3 MessageFormat (android.icu.text.MessageFormat)2 PluralRules (android.icu.text.PluralRules)2 DecimalFormat (android.icu.text.DecimalFormat)1 DecimalFormatSymbols (android.icu.text.DecimalFormatSymbols)1 ULocale (android.icu.util.ULocale)1 FieldPosition (java.text.FieldPosition)1 ParsePosition (java.text.ParsePosition)1