Search in sources :

Example 21 with DecimalFormatSymbols

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());
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 22 with DecimalFormatSymbols

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));
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Example 23 with DecimalFormatSymbols

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));
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Example 24 with DecimalFormatSymbols

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());
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Example 25 with DecimalFormatSymbols

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.));
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Aggregations

DecimalFormatSymbols (java.text.DecimalFormatSymbols)133 DecimalFormat (java.text.DecimalFormat)93 NumberFormat (java.text.NumberFormat)14 Locale (java.util.Locale)13 ParseException (java.text.ParseException)8 BigDecimal (java.math.BigDecimal)7 Currency (java.util.Currency)7 ObjectInputStream (java.io.ObjectInputStream)6 Test (org.junit.Test)6 IOException (java.io.IOException)5 ParsePosition (java.text.ParsePosition)5 BufferedChecksumIndexInput (org.apache.lucene.store.BufferedChecksumIndexInput)5 ChecksumIndexInput (org.apache.lucene.store.ChecksumIndexInput)5 IndexInput (org.apache.lucene.store.IndexInput)5 BytesRefBuilder (org.apache.lucene.util.BytesRefBuilder)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 ObjectOutputStream (java.io.ObjectOutputStream)4 BytesRef (org.apache.lucene.util.BytesRef)4 ArrayList (java.util.ArrayList)3