use of android.icu.text.DecimalFormat in project j2objc by google.
the class MyNumberFormat method Test4099404.
/**
* Tests all different comments.
* Response to some comments :
* [1] DecimalFormat.parse API documentation is more than just one line.
* This is not a reproducable doc error in 116 source code.
* [2] See updated javadoc.
* [3] Fixed.
* [4] NumberFormat.parse(String, ParsePosition) : If parsing fails,
* a null object will be returned. The unchanged parse position also
* reflects an error.
* NumberFormat.parse(String) : If parsing fails, an ParseException
* will be thrown.
* See updated javadoc for more details.
* [5] See updated javadoc.
* [6] See updated javadoc.
* [7] This is a correct behavior if the DateFormat object is linient.
* Otherwise, an IllegalArgumentException will be thrown when formatting
* "January 35". See GregorianCalendar class javadoc for more details.
*/
@Test
public void Test4099404() {
try {
DecimalFormat fmt = new DecimalFormat("000.0#0");
// fix "The variable 'fmt' is never used"
logln("format 3456.78: " + fmt.format(3456.78));
errln("Bug 4099404 failed applying illegal pattern \"000.0#0\"");
} catch (Exception foo) {
logln("Bug 4099404 pattern \"000.0#0\" passed");
}
try {
DecimalFormat fmt = new DecimalFormat("0#0.000");
// fix "The variable 'fmt' is never used"
logln("format 3456.78: " + fmt.format(3456.78));
errln("Bug 4099404 failed applying illegal pattern \"0#0.000\"");
} catch (Exception foo) {
logln("Bug 4099404 pattern \"0#0.000\" passed");
}
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestWhiteSpaceParsing.
@Test
public void TestWhiteSpaceParsing() {
DecimalFormatSymbols US = new DecimalFormatSymbols(Locale.US);
DecimalFormat fmt = new DecimalFormat("a b#0c ", US);
int n = 1234;
expect(fmt, "a b1234c ", n);
expect(fmt, "a b1234c ", n);
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestFieldPositionFraction.
@Test
public void TestFieldPositionFraction() {
DecimalFormat nf = (DecimalFormat) android.icu.text.NumberFormat.getInstance(ULocale.ENGLISH);
nf.setPositivePrefix("FOO");
nf.setPositiveSuffix("BA");
StringBuffer buffer = new StringBuffer();
FieldPosition fp = new FieldPosition(NumberFormat.Field.FRACTION);
nf.format(35.47, buffer, fp);
assertEquals("35.47", "FOO35.47BA", buffer.toString());
assertEquals("fp begin", 6, fp.getBeginIndex());
assertEquals("fp end", 8, fp.getEndIndex());
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestNegZeroRounding.
/*
* Testing rounding to negative zero problem
* reported by ticket#7609
*/
@Test
public void TestNegZeroRounding() {
DecimalFormat df = (DecimalFormat) NumberFormat.getInstance();
df.setRoundingMode(MathContext.ROUND_HALF_UP);
df.setMinimumFractionDigits(1);
df.setMaximumFractionDigits(1);
String text1 = df.format(-0.01);
df.setRoundingIncrement(0.1);
String text2 = df.format(-0.01);
// output1 and output2 must be identical
if (!text1.equals(text2)) {
errln("NumberFormat.format() should return the same result - text1=" + text1 + " text2=" + text2);
}
}
use of android.icu.text.DecimalFormat in project j2objc by google.
the class NumberFormatTest method TestFormatToCharacterIteratorIssue11805.
// Testing for Issue 11805.
@Test
public void TestFormatToCharacterIteratorIssue11805() {
final double number = -350.76;
DecimalFormat dfUS = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.US);
String strUS = dfUS.format(number);
Set<AttributedCharacterIterator.Attribute> resultUS = dfUS.formatToCharacterIterator(number).getAllAttributeKeys();
assertEquals("Negative US Results: " + strUS, 5, resultUS.size());
// For each test, add assert that all the fields are present and in the right spot.
// TODO: Add tests for identify and position of each field, as in IntlTestDecimalFormatAPIC.
DecimalFormat dfDE = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.GERMANY);
String strDE = dfDE.format(number);
Set<AttributedCharacterIterator.Attribute> resultDE = dfDE.formatToCharacterIterator(number).getAllAttributeKeys();
assertEquals("Negative DE Results: " + strDE, 5, resultDE.size());
DecimalFormat dfIN = (DecimalFormat) DecimalFormat.getCurrencyInstance(new Locale("hi", "in"));
String strIN = dfIN.format(number);
Set<AttributedCharacterIterator.Attribute> resultIN = dfIN.formatToCharacterIterator(number).getAllAttributeKeys();
assertEquals("Negative IN Results: " + strIN, 5, resultIN.size());
DecimalFormat dfJP = (DecimalFormat) DecimalFormat.getCurrencyInstance(Locale.JAPAN);
String strJP = dfJP.format(number);
Set<AttributedCharacterIterator.Attribute> resultJP = dfJP.formatToCharacterIterator(number).getAllAttributeKeys();
assertEquals("Negative JA Results: " + strJP, 3, resultJP.size());
DecimalFormat dfGB = (DecimalFormat) DecimalFormat.getCurrencyInstance(new Locale("en", "gb"));
String strGB = dfGB.format(number);
Set<AttributedCharacterIterator.Attribute> resultGB = dfGB.formatToCharacterIterator(number).getAllAttributeKeys();
assertEquals("Negative GB Results: " + strGB, 5, resultGB.size());
DecimalFormat dfPlural = (DecimalFormat) NumberFormat.getInstance(new Locale("en", "gb"), NumberFormat.PLURALCURRENCYSTYLE);
strGB = dfPlural.format(number);
resultGB = dfPlural.formatToCharacterIterator(number).getAllAttributeKeys();
assertEquals("Negative GB Results: " + strGB, 5, resultGB.size());
strGB = dfPlural.format(1);
resultGB = dfPlural.formatToCharacterIterator(1).getAllAttributeKeys();
assertEquals("Negative GB Results: " + strGB, 4, resultGB.size());
// Test output with unit value.
DecimalFormat auPlural = (DecimalFormat) NumberFormat.getInstance(new Locale("en", "au"), NumberFormat.PLURALCURRENCYSTYLE);
String strAU = auPlural.format(1L);
Set<AttributedCharacterIterator.Attribute> resultAU = auPlural.formatToCharacterIterator(1L).getAllAttributeKeys();
assertEquals("Unit AU Result: " + strAU, 4, resultAU.size());
// Verify Permille fields.
DecimalFormatSymbols sym = new DecimalFormatSymbols(new Locale("en", "gb"));
DecimalFormat dfPermille = new DecimalFormat("####0.##\u2030", sym);
strGB = dfPermille.format(number);
resultGB = dfPermille.formatToCharacterIterator(number).getAllAttributeKeys();
assertEquals("Negative GB Permille Results: " + strGB, 3, resultGB.size());
}
Aggregations