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()));
}
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);
}
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());
}
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));
}
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;
}
Aggregations