use of android.icu.text.CompactDecimalFormat in project j2objc by google.
the class CompactDecimalFormatTest method TestDefaultSignificantDigits.
@Test
public void TestDefaultSignificantDigits() {
// We are expecting two significant digits as default.
CompactDecimalFormat cdf = CompactDecimalFormat.getInstance(ULocale.ENGLISH, CompactStyle.SHORT);
assertEquals("Default significant digits", "12K", cdf.format(12345));
assertEquals("Default significant digits", "1.2K", cdf.format(1234));
assertEquals("Default significant digits", "120", cdf.format(123));
}
use of android.icu.text.CompactDecimalFormat in project j2objc by google.
the class CompactDecimalFormatTest method TestCharacterIterator.
@Test
public void TestCharacterIterator() {
CompactDecimalFormat cdf = getCDFInstance(ULocale.forLanguageTag("sw"), CompactStyle.SHORT);
AttributedCharacterIterator iter = cdf.formatToCharacterIterator(1234567);
assertEquals("CharacterIterator", "M1.2", iterToString(iter));
iter = cdf.formatToCharacterIterator(1234567);
iter.setIndex(1);
assertEquals("Attributes", NumberFormat.Field.INTEGER, iter.getAttribute(NumberFormat.Field.INTEGER));
assertEquals("Attributes", 1, iter.getRunStart());
assertEquals("Attributes", 2, iter.getRunLimit());
}
use of android.icu.text.CompactDecimalFormat in project j2objc by google.
the class CompactDecimalFormatTest method TestBug12422.
@Test
public void TestBug12422() {
CompactDecimalFormat cdf;
String result;
// Bug #12422
cdf = CompactDecimalFormat.getInstance(new ULocale("ar", "SA"), CompactDecimalFormat.CompactStyle.LONG);
result = cdf.format(43000);
assertEquals("CDF should correctly format 43000 in 'ar'", "٤٣ ألف", result);
// Bug #12449
cdf = CompactDecimalFormat.getInstance(new ULocale("ar"), CompactDecimalFormat.CompactStyle.SHORT);
cdf.setMaximumSignificantDigits(3);
result = cdf.format(1234);
assertEquals("CDF should correctly format 1234 with 3 significant digits in 'ar'", "١٫٢٣ ألف", result);
// Check currency formatting as well
cdf = CompactDecimalFormat.getInstance(new ULocale("ar"), CompactDecimalFormat.CompactStyle.SHORT);
result = cdf.format(new CurrencyAmount(43000f, Currency.getInstance("USD")));
assertEquals("CDF should correctly format 43000 with currency in 'ar'", "US$ ٤٣ ألف", result);
result = cdf.format(new CurrencyAmount(-43000f, Currency.getInstance("USD")));
assertEquals("CDF should correctly format -43000 with currency in 'ar'", "US$ -٤٣ ألف", result);
// Extra locale with different positive/negative formats
cdf = CompactDecimalFormat.getInstance(new ULocale("fi"), CompactDecimalFormat.CompactStyle.SHORT);
result = cdf.format(new CurrencyAmount(43000f, Currency.getInstance("USD")));
assertEquals("CDF should correctly format 43000 with currency in 'fi'", "43 t. $", result);
result = cdf.format(new CurrencyAmount(-43000f, Currency.getInstance("USD")));
assertEquals("CDF should correctly format -43000 with currency in 'fi'", "−43 t. $", result);
}
Aggregations