use of org.apache.tapestry5.internal.translator.BigDecimalNumericFormatter in project tapestry-5 by apache.
the class TranslatorSourceImplTest method bigdecimal_with_localized_symbols.
@Test
public void bigdecimal_with_localized_symbols() throws ParseException {
DecimalFormatSymbols symbols = new DecimalFormatSymbols(Locale.ENGLISH);
symbols.setGroupingSeparator('_');
symbols.setMinusSign('*');
symbols.setDecimalSeparator('#');
BigDecimalNumericFormatter f = new BigDecimalNumericFormatter(symbols);
BigDecimal big = new BigDecimal("-123456.797956563434");
assertEquals(f.parse("*123_456#797956563434"), big);
assertEquals(f.toClient(big), "*123456#797956563434");
}
use of org.apache.tapestry5.internal.translator.BigDecimalNumericFormatter in project tapestry-5 by apache.
the class NumericTranslatorSupportImpl method getOutputFormatter.
private NumericFormatter getOutputFormatter(Class type) {
Locale locale = threadLocale.getLocale();
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
if (type.equals(BigInteger.class))
return new BigIntegerNumericFormatter(symbols);
if (type.equals(BigDecimal.class))
return new BigDecimalNumericFormatter(symbols);
if (!isIntegerType(type)) {
NumberFormat format = NumberFormat.getNumberInstance(locale);
return new NumericFormatterImpl(format);
}
DecimalFormat df = new DecimalFormat(toString(symbols.getZeroDigit()), symbols);
return new NumericFormatterImpl(df);
}
use of org.apache.tapestry5.internal.translator.BigDecimalNumericFormatter in project tapestry-5 by apache.
the class NumericTranslatorSupportImpl method getParseFormatter.
private NumericFormatter getParseFormatter(Class type) {
Locale locale = threadLocale.getLocale();
DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
if (type.equals(BigInteger.class))
return new BigIntegerNumericFormatter(symbols);
if (type.equals(BigDecimal.class))
return new BigDecimalNumericFormatter(symbols);
if (isIntegerType(type)) {
NumberFormat format = NumberFormat.getIntegerInstance(locale);
return new NumericFormatterImpl(format);
}
DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(locale);
if (type.equals(BigDecimal.class))
df.setParseBigDecimal(true);
return new NumericFormatterImpl(df);
}
Aggregations