use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_getCurrency.
public void test_getCurrency() {
Currency currK = Currency.getInstance("KRW");
Currency currX = Currency.getInstance("XXX");
Currency currE = Currency.getInstance("EUR");
DecimalFormat df = (DecimalFormat) NumberFormat.getCurrencyInstance(new Locale("ko", "KR"));
assertTrue("Test1: Returned incorrect currency", df.getCurrency() == currK);
df = (DecimalFormat) NumberFormat.getCurrencyInstance(new Locale("", "KR"));
assertTrue("Test2: Returned incorrect currency", df.getCurrency() == currK);
df = (DecimalFormat) NumberFormat.getCurrencyInstance(new Locale("ko", ""));
assertTrue("Test3: Returned incorrect currency", df.getCurrency() == currX);
df = (DecimalFormat) NumberFormat.getCurrencyInstance(new Locale("fr", "FR"));
assertTrue("Test4: Returned incorrect currency", df.getCurrency() == currE);
// Regression for HARMONY-1351
df = (DecimalFormat) NumberFormat.getCurrencyInstance(new Locale("QWERTY"));
assertTrue("Test5: Returned incorrect currency", df.getCurrency() == currX);
// JDK fails these tests since it doesn't have the PREEURO variant
// df = (DecimalFormat)NumberFormat.getCurrencyInstance(new Locale("fr",
// "FR","PREEURO"));
// assertTrue("Test5: Returned incorrect currency", df.getCurrency() ==
// currF);
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method testAttributedCharacterIterator.
public void testAttributedCharacterIterator() throws Exception {
// Regression for http://issues.apache.org/jira/browse/HARMONY-333
AttributedCharacterIterator iterator = new DecimalFormat().formatToCharacterIterator(new Integer(1));
assertNotNull(iterator);
assertFalse("attributes should exist", iterator.getAttributes().isEmpty());
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_formatDouble_maxFractionDigits.
// See also the _formatDouble tests. This tests a subset of patterns / values.
/* J2ObjC: Our DecimalFormat implementation is compatible with the RI, not Android
public void test_formatLong_scientificNotation() {
FormatTester formatTester = new FormatTester();
final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
DecimalFormat df = new DecimalFormat("00.0#E0", dfs);
// ["00.0#E0",isDecimalSeparatorAlwaysShown=false,groupingSize=0,multiplier=1,
// negativePrefix=-,negativeSuffix=,positivePrefix=,positiveSuffix=,maxIntegerDigits=2,
// maxFractionDigits=2,minIntegerDigits=2,minFractionDigits=1,grouping=false]
// Because maximum integer digit was not explicitly set: The exponent can be any integer.
// Scientific notation => use significant digit logic
// '@' not present: Significant digits: Min: 1,
// Max: "min integer digits" (2) + "max fractional digits (2) == 4
formatTester.format(df, "00.0E0", 0);
formatTester.format(df, "10.0E-1", 1);
formatTester.format(df, "12.0E0", 12);
formatTester.format(df, "12.3E1", 123);
formatTester.format(df, "12.34E2", 1234);
formatTester.format(df, "12.35E3", 12346);
formatTester.format(df, "10.0E4", 99999);
formatTester.format(df, "-10.0E-1", -1);
formatTester.format(df, "-12.0E0", -12);
formatTester.format(df, "-12.3E1", -123);
formatTester.format(df, "-12.34E2", -1234);
formatTester.format(df, "-12.35E3", -12346);
formatTester.format(df, "-10.0E4", -99999);
df = new DecimalFormat("##0.0E0", dfs);
// ["##0.0E0",isDecimalSeparatorAlwaysShown=false,groupingSize=0,multiplier=1,
// negativePrefix=-,negativeSuffix=,positivePrefix=,positiveSuffix=,maxIntegerDigits=3,
// maxFractionDigits=1,minIntegerDigits=1,minFractionDigits=1,grouping=false]
// Because maximum integer digit count is set: The exponent must be a multiple of it (3).
// Scientific notation => use significant digit logic
// '@' not present: Significant digits: Min: 1,
// Max: "min integer digits" (1) + "max fractional digits (1) == 2
formatTester.format(df, "0.0E0", 0);
formatTester.format(df, "1.0E0", 1);
formatTester.format(df, "12E0", 12);
formatTester.format(df, "120E0", 123);
formatTester.format(df, "1.2E3", 1234);
formatTester.format(df, "12E3", 12346);
formatTester.format(df, "100E3", 99999);
formatTester.format(df, "1.0E6", 999999);
df = new DecimalFormat("#00.0##E0", dfs);
// ["##0.0E0",isDecimalSeparatorAlwaysShown=false,groupingSize=0,multiplier=1,
// negativePrefix=-,negativeSuffix=,positivePrefix=,positiveSuffix=,maxIntegerDigits=3,
// maxFractionDigits=1,minIntegerDigits=1,minFractionDigits=1,grouping=false]
// Because maximum integer digit count is set: The exponent must be a multiple of it (3).
// Scientific notation => use significant digit logic
// '@' not present: Significant digits: Min: 1,
// Max: "min integer digits" (2) + "max fractional digits (3) == 5
formatTester.format(df, "0.0E0", 0);
formatTester.format(df, "1.0E0", 1);
formatTester.format(df, "12E0", 12);
formatTester.format(df, "123E0", 123);
formatTester.format(df, "1.234E3", 1234);
formatTester.format(df, "12.345E3", 12345);
formatTester.format(df, "123.46E3", 123456);
formatTester.format(df, "1.2346E6", 1234567);
formatTester.format(df, "12.346E6", 12345678);
formatTester.format(df, "100E6", 99999999);
df = new DecimalFormat("#.0E0", dfs);
// ["#.0E0",isDecimalSeparatorAlwaysShown=false,groupingSize=0,multiplier=1,
// negativePrefix=-,negativeSuffix=,positivePrefix=,positiveSuffix=,maxIntegerDigits=1,
// maxFractionDigits=1,minIntegerDigits=0,minFractionDigits=1,grouping=false]
// Because maximum integer digit count is set: The exponent must be a multiple of it (1).
// Scientific notation => use significant digit logic
// '@' not present: Significant digits: Min: 1,
// Max: "min integer digits" (0) + "max fractional digits (1) == 1
formatTester.format(df, "0.0E0", 0);
formatTester.format(df, "1.0E0", 1);
formatTester.format(df, "1.0E1", 12);
formatTester.format(df, "1.0E2", 123);
formatTester.format(df, "1.0E3", 1234);
formatTester.format(df, "1.0E4", 9999);
df = new DecimalFormat("0.#E0", dfs);
// ["0.#E0",isDecimalSeparatorAlwaysShown=false,groupingSize=0,multiplier=1,
// negativePrefix=-,negativeSuffix=,positivePrefix=,positiveSuffix=,maxIntegerDigits=1,
// maxFractionDigits=1,minIntegerDigits=1,minFractionDigits=0,grouping=false]
// Because maximum integer digit was not explicitly set: The exponent can be any integer.
// Scientific notation => use significant digit logic
// '@' not present: Significant digits: Min: 1,
// Max: "min integer digits" (1) + "max fractional digits (1) == 2
formatTester.format(df, "0E0", 0);
formatTester.format(df, "1E0", 1);
formatTester.format(df, "1.2E1", 12);
formatTester.format(df, "1.2E2", 123);
formatTester.format(df, "1.2E3", 1234);
formatTester.format(df, "1E4", 9999);
df = new DecimalFormat(".0E0", dfs);
// [".0E0",isDecimalSeparatorAlwaysShown=true,groupingSize=0,multiplier=1,negativePrefix=-,
// negativeSuffix=,positivePrefix=,positiveSuffix=,maxIntegerDigits=0,maxFractionDigits=1,
// minIntegerDigits=0,minFractionDigits=1,grouping=false]
// Because maximum integer digit was not explicitly set: The exponent can be any integer.
// Scientific notation => use significant digit logic
// '@' not present: Significant digits: Min: 1,
// Max: "min integer digits" (0) + "max fractional digits (1) == 1
formatTester.format(df, ".0E0", 0);
formatTester.format(df, ".1E1", 1);
formatTester.format(df, ".1E2", 12);
formatTester.format(df, ".1E3", 123);
formatTester.format(df, ".1E4", 1234);
formatTester.format(df, ".1E5", 9999);
formatTester.throwFailures();
}*/
// Demonstrates that fraction digit rounding occurs as expected with 1, 10 and 14 fraction
// digits, using numbers that are well within the precision of IEEE 754.
public void test_formatDouble_maxFractionDigits() {
final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
DecimalFormat format = new DecimalFormat("#0.#", dfs);
format.setGroupingUsed(false);
format.setMaximumIntegerDigits(400);
format.setMaximumFractionDigits(1);
assertEquals("1", format.format(0.99));
assertEquals("1", format.format(0.95));
assertEquals("0.9", format.format(0.94));
assertEquals("0.9", format.format(0.90));
assertEquals("0.2", format.format(0.19));
assertEquals("0.2", format.format(0.15));
assertEquals("0.1", format.format(0.14));
assertEquals("0.1", format.format(0.10));
format.setMaximumFractionDigits(10);
assertEquals("1", format.format(0.99999999999));
assertEquals("1", format.format(0.99999999995));
assertEquals("0.9999999999", format.format(0.99999999994));
assertEquals("0.9999999999", format.format(0.99999999990));
assertEquals("0.1111111112", format.format(0.11111111119));
assertEquals("0.1111111112", format.format(0.11111111115));
assertEquals("0.1111111111", format.format(0.11111111114));
assertEquals("0.1111111111", format.format(0.11111111110));
format.setMaximumFractionDigits(14);
assertEquals("1", format.format(0.999999999999999));
assertEquals("1", format.format(0.999999999999995));
assertEquals("0.99999999999999", format.format(0.999999999999994));
assertEquals("0.99999999999999", format.format(0.999999999999990));
assertEquals("0.11111111111112", format.format(0.111111111111119));
assertEquals("0.11111111111112", format.format(0.111111111111115));
assertEquals("0.11111111111111", format.format(0.111111111111114));
assertEquals("0.11111111111111", format.format(0.111111111111110));
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method testMaximumIntegerDigits_getAndSet.
public void testMaximumIntegerDigits_getAndSet() {
// When use default locale, in this case zh_CN
// the returned instance of NumberFormat is a DecimalFormat
DecimalFormat form = new DecimalFormat("00.###E0");
assertEquals(2, form.getMaximumIntegerDigits());
form = (DecimalFormat) NumberFormat.getInstance(Locale.US);
form.setMaximumIntegerDigits(300);
assertEquals(300, form.getMaximumIntegerDigits());
// Deliberately > 309. The API docs mention 309 and suggest that you can set the value
// higher but it will use 309 as a ceiling.
form.setMaximumIntegerDigits(500);
assertEquals(500, form.getMaximumIntegerDigits());
form = new DecimalFormat("00.###E0");
assertEquals(2, form.getMaximumIntegerDigits());
form.setMaximumIntegerDigits(500);
assertEquals(500, form.getMaximumIntegerDigits());
form.format(12.3);
assertEquals(500, form.getMaximumIntegerDigits());
form.setMaximumIntegerDigits(-3);
assertEquals(0, form.getMaximumIntegerDigits());
// regression test for HARMONY-878
assertTrue(new DecimalFormat("0\t'0'").getMaximumIntegerDigits() > 0);
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_equals.
public void test_equals() {
DecimalFormat format = (DecimalFormat) NumberFormat.getInstance(Locale.US);
DecimalFormat cloned = (DecimalFormat) format.clone();
cloned.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
assertEquals(format, cloned);
Currency c = Currency.getInstance(Locale.US);
cloned.setCurrency(c);
assertEquals(format, cloned);
}
Aggregations