use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatSpecificationTest method formatFrWithPattern.
private static String formatFrWithPattern(double d, String pattern) {
DecimalFormatSymbols sym = new DecimalFormatSymbols(ULocale.FRANCE);
DecimalFormat fmt = new DecimalFormat(pattern, sym);
return fmt.format(d).replace('\u00a0', ' ');
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class TestMessageFormat method testNumericOnlyMethods.
// Ensure that methods designed for numeric arguments only, will throw
// an exception when called on MessageFormat objects created with
// named arguments.
@Test
public void testNumericOnlyMethods() {
MessageFormat msg = new MessageFormat("Number of files: {numfiles}");
boolean gotException = false;
try {
Format[] fmts = { new DecimalFormat() };
msg.setFormatsByArgumentIndex(fmts);
} catch (IllegalArgumentException e) {
gotException = true;
}
if (!gotException) {
errln("MessageFormat.setFormatsByArgumentIndex() should throw an " + "IllegalArgumentException when called on formats with " + "named arguments but did not!");
}
gotException = false;
try {
msg.setFormatByArgumentIndex(0, new DecimalFormat());
} catch (IllegalArgumentException e) {
gotException = true;
}
if (!gotException) {
errln("MessageFormat.setFormatByArgumentIndex() should throw an " + "IllegalArgumentException when called on formats with " + "named arguments but did not!");
}
gotException = false;
try {
msg.getFormatsByArgumentIndex();
} catch (IllegalArgumentException e) {
gotException = true;
}
if (!gotException) {
errln("MessageFormat.getFormatsByArgumentIndex() should throw an " + "IllegalArgumentException when called on formats with " + "named arguments but did not!");
}
gotException = false;
try {
Object[] args = { new Long(42) };
msg.format(args, new StringBuffer(), new FieldPosition(0));
} catch (IllegalArgumentException e) {
gotException = true;
}
if (!gotException) {
errln("MessageFormat.format(Object[], StringBuffer, FieldPosition) " + "should throw an IllegalArgumentException when called on " + "formats with named arguments but did not!");
}
gotException = false;
try {
Object[] args = { new Long(42) };
msg.format((Object) args, new StringBuffer(), new FieldPosition(0));
} catch (IllegalArgumentException e) {
gotException = true;
}
if (!gotException) {
errln("MessageFormat.format(Object, StringBuffer, FieldPosition) " + "should throw an IllegalArgumentException when called with " + "non-Map object as argument on formats with named " + "arguments but did not!");
}
gotException = false;
try {
msg.parse("Number of files: 5", new ParsePosition(0));
} catch (IllegalArgumentException e) {
gotException = true;
}
if (!gotException) {
errln("MessageFormat.parse(String, ParsePosition) " + "should throw an IllegalArgumentException when called with " + "non-Map object as argument on formats with named " + "arguments but did not!");
}
gotException = false;
try {
msg.parse("Number of files: 5");
} catch (IllegalArgumentException e) {
gotException = true;
} catch (ParseException e) {
errln("Wrong exception thrown.");
}
if (!gotException) {
errln("MessageFormat.parse(String) " + "should throw an IllegalArgumentException when called with " + "non-Map object as argument on formats with named " + "arguments but did not!");
}
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class TestMessageFormat method TestSetFormat.
@Test
public void TestSetFormat() {
MessageFormat ms = new MessageFormat("{number} {date}", ULocale.ENGLISH);
final DecimalFormat decimalFormat = new DecimalFormat("000.000", DecimalFormatSymbols.getInstance(ULocale.ENGLISH));
ms.setFormatByArgumentName("number", decimalFormat);
final SimpleDateFormat dateFormat = new SimpleDateFormat("'year:'yy 'month:'MM 'day:'dd");
dateFormat.setTimeZone(TimeZone.getTimeZone("Etc/GMT"));
ms.setFormatByArgumentName("date", dateFormat);
Map map = new HashMap();
map.put("number", new Integer(1234));
map.put("date", new Date(0, 0, 0));
String result = ms.format(map);
assertEquals("setFormatByArgumentName", "1234.000 year:99 month:12 day:31", result);
Set formatNames = ms.getArgumentNames();
assertEquals("Format Names match", formatNames, map.keySet());
assertEquals("Decimal", decimalFormat, ms.getFormatByArgumentName("number"));
assertEquals("Date", dateFormat, ms.getFormatByArgumentName("date"));
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class ScientificNumberFormatterTest method TestFixedDecimalSuperscript.
@Test
public void TestFixedDecimalSuperscript() {
DecimalFormat decfmt = (DecimalFormat) NumberFormat.getInstance(ULocale.ENGLISH);
ScientificNumberFormatter fmt = ScientificNumberFormatter.getSuperscriptInstance(decfmt);
assertEquals("", "123,456", fmt.format(123456.0));
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class BigNumberFormatTest method Test4161100.
@Test
public void Test4161100() {
NumberFormat f = NumberFormat.getInstance();
f.setMinimumFractionDigits(1);
f.setMaximumFractionDigits(1);
double a = -0.09;
String s = f.format(a);
logln(a + " x " + ((DecimalFormat) f).toPattern() + " = " + s);
if (!s.equals("-0.1")) {
errln("FAIL");
}
}
Aggregations