Search in sources :

Example 91 with DecimalFormatSymbols

use of java.text.DecimalFormatSymbols in project j2objc by google.

the class DecimalFormatTest method test_parse_infinityBigDecimalFalse.

public void test_parse_infinityBigDecimalFalse() {
    // Regression test for HARMONY-106
    DecimalFormat format = (DecimalFormat) NumberFormat.getInstance();
    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    Number number = format.parse(symbols.getInfinity(), new ParsePosition(0));
    assertTrue(number instanceof Double);
    assertTrue(Double.isInfinite(number.doubleValue()));
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) ParsePosition(java.text.ParsePosition)

Example 92 with DecimalFormatSymbols

use of java.text.DecimalFormatSymbols in project j2objc by google.

the class DecimalFormatSymbolsTest method testSerialization.

// http://code.google.com/p/android/issues/detail?id=14495
public void testSerialization() throws Exception {
    DecimalFormatSymbols originalDfs = DecimalFormatSymbols.getInstance(Locale.GERMANY);
    // Serialize...
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    new ObjectOutputStream(out).writeObject(originalDfs);
    byte[] bytes = out.toByteArray();
    // Deserialize...
    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
    DecimalFormatSymbols deserializedDfs = (DecimalFormatSymbols) in.readObject();
    assertEquals(-1, in.read());
    // The two objects should claim to be equal.
    assertEquals(originalDfs, deserializedDfs);
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 93 with DecimalFormatSymbols

use of java.text.DecimalFormatSymbols in project j2objc by google.

the class DecimalFormatSymbolsTest method testSetNulInternationalCurrencySymbol.

//    // https://code.google.com/p/android/issues/detail?id=79925
//    public void testSetSameCurrency() throws Exception {
//        DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
//        dfs.setCurrency(Currency.getInstance("USD"));
//        assertEquals("$", dfs.getCurrencySymbol());
//        dfs.setCurrencySymbol("poop");
//        assertEquals("poop", dfs.getCurrencySymbol());
//        dfs.setCurrency(Currency.getInstance("USD"));
//        assertEquals("$", dfs.getCurrencySymbol());
//    }
public void testSetNulInternationalCurrencySymbol() throws Exception {
    Currency usd = Currency.getInstance("USD");
    DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
    dfs.setCurrency(usd);
    assertEquals(usd, dfs.getCurrency());
    assertEquals("$", dfs.getCurrencySymbol());
    assertEquals("USD", dfs.getInternationalCurrencySymbol());
    // Setting the international currency symbol to null sets the currency to null too,
    // but not the currency symbol.
    dfs.setInternationalCurrencySymbol(null);
    assertEquals(null, dfs.getCurrency());
    assertEquals("$", dfs.getCurrencySymbol());
    assertEquals(null, dfs.getInternationalCurrencySymbol());
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) Currency(java.util.Currency)

Example 94 with DecimalFormatSymbols

use of java.text.DecimalFormatSymbols in project j2objc by google.

the class DecimalFormatTest method testSetZeroDigitForPattern.

public void testSetZeroDigitForPattern() {
    DecimalFormatSymbols decimalFormatSymbols = new DecimalFormatSymbols();
    decimalFormatSymbols.setZeroDigit('a');
    DecimalFormat formatter = new DecimalFormat();
    formatter.setDecimalFormatSymbols(decimalFormatSymbols);
    formatter.applyLocalizedPattern("#.aa");
    assertEquals("e.fa", formatter.format(4.50));
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Example 95 with DecimalFormatSymbols

use of java.text.DecimalFormatSymbols in project robovm by robovm.

the class ElemNumber method getNumberFormatter.

/**
   * Get the number formatter to be used the format the numbers
   *
   * @param transformer non-null reference to the the current transform-time state.
   * @param contextNode The node that "." expresses.
   *
   * ($objectName$) @return The number formatter to be used
   *
   * @throws TransformerException
   */
private DecimalFormat getNumberFormatter(TransformerImpl transformer, int contextNode) throws TransformerException {
    // Patch from Steven Serocki
    // Maybe we really want to do the clone in getLocale() and return  
    // a clone of the default Locale??
    Locale locale = (Locale) getLocale(transformer, contextNode).clone();
    // Helper to format local specific numbers to strings.
    DecimalFormat formatter = null;
    //synchronized (locale)
    //{
    //     formatter = (DecimalFormat) NumberFormat.getNumberInstance(locale);
    //}
    String digitGroupSepValue = (null != m_groupingSeparator_avt) ? m_groupingSeparator_avt.evaluate(transformer.getXPathContext(), contextNode, this) : null;
    // validated statically in XSLTAttributeDef.java.
    if ((digitGroupSepValue != null) && (!m_groupingSeparator_avt.isSimple()) && (digitGroupSepValue.length() != 1)) {
        transformer.getMsgMgr().warn(this, XSLTErrorResources.WG_ILLEGAL_ATTRIBUTE_VALUE, new Object[] { Constants.ATTRNAME_NAME, m_groupingSeparator_avt.getName() });
    }
    String nDigitsPerGroupValue = (null != m_groupingSize_avt) ? m_groupingSize_avt.evaluate(transformer.getXPathContext(), contextNode, this) : null;
    // TODO: Handle digit-group attributes
    if ((null != digitGroupSepValue) && (null != nDigitsPerGroupValue) && // Ignore if separation value is empty string
    (digitGroupSepValue.length() > 0)) {
        try {
            formatter = (DecimalFormat) NumberFormat.getNumberInstance(locale);
            formatter.setGroupingSize(Integer.valueOf(nDigitsPerGroupValue).intValue());
            DecimalFormatSymbols symbols = formatter.getDecimalFormatSymbols();
            symbols.setGroupingSeparator(digitGroupSepValue.charAt(0));
            formatter.setDecimalFormatSymbols(symbols);
            formatter.setGroupingUsed(true);
        } catch (NumberFormatException ex) {
            formatter.setGroupingUsed(false);
        }
    }
    return formatter;
}
Also used : Locale(java.util.Locale) 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