use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_setMaximumFractionDigitsAffectsRoundingMode.
public void test_setMaximumFractionDigitsAffectsRoundingMode() throws Exception {
DecimalFormat df = (DecimalFormat) DecimalFormat.getInstance(Locale.US);
df.setMaximumFractionDigits(0);
df.setRoundingMode(RoundingMode.HALF_UP);
assertEquals("-0", df.format(-0.2));
df.setMaximumFractionDigits(1);
assertEquals("-0.2", df.format(-0.2));
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method assertDecFmtWithMultiplierAndFractionByLocale.
private void assertDecFmtWithMultiplierAndFractionByLocale(String value, int multiplier, int fraction, Locale locale, String expectedResult) {
DecimalFormat df = (DecimalFormat) NumberFormat.getIntegerInstance(locale);
df.setMultiplier(multiplier);
df.setMaximumFractionDigits(fraction);
BigDecimal d = new BigDecimal(value);
assertEquals(expectedResult, df.format(d));
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method testSetCurrencySymbol.
// Test that overriding the currency symbol survives a roundrip through the
// DecimalFormat constructor.
// http://b/28732330
public void testSetCurrencySymbol() {
DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols(Locale.US);
decimalFormatSymbols.setCurrencySymbol("¥");
DecimalFormat decimalFormat = new DecimalFormat("¤#,##0.00", decimalFormatSymbols);
assertEquals("¥", decimalFormat.getDecimalFormatSymbols().getCurrencySymbol());
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method test_exponentSeparator.
public void test_exponentSeparator() throws Exception {
DecimalFormat df = new DecimalFormat("0E0");
assertEquals("1E4", df.format(12345.));
DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();
dfs.setExponentSeparator("-useless-api-");
df.setDecimalFormatSymbols(dfs);
assertEquals("1-useless-api-4", df.format(12345.));
}
use of java.text.DecimalFormat in project j2objc by google.
the class DecimalFormatTest method testBug15081434.
// Check we don't crash on null inputs.
public void testBug15081434() throws Exception {
DecimalFormat df = (DecimalFormat) NumberFormat.getCurrencyInstance(Locale.US);
try {
df.parse(null);
fail();
} catch (NullPointerException expected) {
}
try {
df.applyLocalizedPattern(null);
fail();
} catch (NullPointerException expected) {
}
try {
df.applyPattern(null);
fail();
} catch (NullPointerException expected) {
}
try {
df.applyPattern(null);
fail();
} catch (NullPointerException expected) {
}
try {
df.format(null, new StringBuffer(), new FieldPosition(0));
fail();
// J2ObjC: Java docs actually specify that IAE is thrown for null input, not NPE.
} catch (IllegalArgumentException expected) {
}
try {
df.parse(null, new ParsePosition(0));
fail();
} catch (NullPointerException expected) {
}
// This just ignores null.
df.setDecimalFormatSymbols(null);
try {
df.setCurrency(null);
fail();
} catch (NullPointerException expected) {
}
// These just ignore null.
df.setNegativePrefix(null);
df.setNegativeSuffix(null);
df.setPositivePrefix(null);
df.setPositiveSuffix(null);
try {
df.setRoundingMode(null);
fail();
} catch (NullPointerException expected) {
}
}
Aggregations