use of java.text.DecimalFormatSymbols in project j2objc by google.
the class DecimalFormatSymbolsTest method testSerializationOfMultiCharNegativeAndPercentage.
// https://code.google.com/p/android/issues/detail?id=170718
public void testSerializationOfMultiCharNegativeAndPercentage() throws Exception {
DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.forLanguageTag("ar-AR"));
// TODO(user): Investigate.
// assertTrue(dfs.getMinusSignString().length() > 1);
// assertTrue(dfs.getPercentString().length() > 1);
// Serialize...
ByteArrayOutputStream out = new ByteArrayOutputStream();
new ObjectOutputStream(out).writeObject(dfs);
byte[] bytes = out.toByteArray();
// Deserialize...
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
DecimalFormatSymbols deserializedDfs = (DecimalFormatSymbols) in.readObject();
assertEquals(-1, in.read());
assertEquals(dfs.getMinusSign(), deserializedDfs.getMinusSign());
assertEquals(dfs.getPercent(), deserializedDfs.getPercent());
}
use of java.text.DecimalFormatSymbols in project j2objc by google.
the class NumberFormatTest method test_issue79925.
// https://code.google.com/p/android/issues/detail?id=79925\
// When switching currency after having initialised a DecimalFormat instance to a currency,
// the symbols are missing.
public void test_issue79925() {
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
nf.setCurrency(Currency.getInstance("EUR"));
assertEquals("€50.00", nf.format(50.0));
DecimalFormatSymbols decimalFormatSymbols = ((DecimalFormat) nf).getDecimalFormatSymbols();
decimalFormatSymbols.setCurrencySymbol("");
((DecimalFormat) nf).setDecimalFormatSymbols(decimalFormatSymbols);
assertEquals("50.00", nf.format(50.0));
nf.setCurrency(Currency.getInstance("SGD"));
assertEquals("SGD50.00", nf.format(50.0));
nf.setCurrency(Currency.getInstance("SGD"));
assertEquals("SGD50.00", nf.format(50.00));
nf.setCurrency(Currency.getInstance("USD"));
assertEquals("$50.00", nf.format(50.0));
nf.setCurrency(Currency.getInstance("SGD"));
assertEquals("SGD50.00", nf.format(50.0));
}
use of java.text.DecimalFormatSymbols in project j2objc by google.
the class NumberFormatTest method test_customCurrencySymbol.
// Test to ensure explicitly setting a currency symbol will overwrite the defaults.
public void test_customCurrencySymbol() {
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
DecimalFormatSymbols dfs = ((DecimalFormat) nf).getDecimalFormatSymbols();
dfs.setCurrencySymbol("SPECIAL");
((DecimalFormat) nf).setDecimalFormatSymbols(dfs);
assertEquals("SPECIAL3.14", nf.format(3.14));
// Setting the currency again should reset the symbols.
nf.setCurrency(Currency.getInstance("USD"));
assertEquals("$3.14", nf.format(3.14));
// Setting it back again should work.
dfs.setCurrencySymbol("NEW");
((DecimalFormat) nf).setDecimalFormatSymbols(dfs);
assertEquals("NEW3.14", nf.format(3.14));
}
use of java.text.DecimalFormatSymbols 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.DecimalFormatSymbols 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.));
}
Aggregations