Following code in Jasper instantiates BigDecimal:
public static Number net.sf.jasperreports.engine.util.FormatUtils#getFormattedNumber(NumberFormat numberFormat, String fieldValue, Class<?> valueClass) throws ParseException {
if (valueClass.equals(Byte.class)) {
return numberFormat.parse(fieldValue).byteValue();
} else if (valueClass.equals(Integer.class)) {
return numberFormat.parse(fieldValue).intValue();
} else if (valueClass.equals(Long.class)) {
return numberFormat.parse(fieldValue).longValue();
} else if (valueClass.equals(Short.class)) {
return numberFormat.parse(fieldValue).shortValue();
} else if (valueClass.equals(Double.class)) {
return numberFormat.parse(fieldValue).doubleValue();
} else if (valueClass.equals(Float.class)) {
return numberFormat.parse(fieldValue).floatValue();
} else if (valueClass.equals(BigDecimal.class)) {
return new BigDecimal(numberFormat.parse(fieldValue).toString());
} else if (valueClass.equals(BigInteger.class)) {
return new BigInteger(String.valueOf(numberFormat.parse(fieldValue).longValue()));
} else {
return valueClass.equals(Number.class) ? numberFormat.parse(fieldValue) : null;
}
}
fieldValue is following String "111111111111111111111111111111.222222222222" but result of numberFormat.parse(fieldValue).toString() returns String without fractional part "111111111111111111111111111111" if NumberFormat instantiated this way:
NumberFormat numberFormat = NumberFormat.getInstance();
DecimalFormat decimalFormat = (DecimalFormat) numberFormat;
decimalFormat.setParseBigDecimal(true);
And may return first 16 numbers "1111111111111111" if only NumberFormat passed as parameter.
There is very complicated logic in java.text.NumberFormat#parse(java.lang.String, java.text.ParsePosition) responsible for parsing fieldValue that comes as String.
Many Thanks for any ideas how to instantiate NumberFormat correct way, so the fractional won't be missed in numberFormat.parse(fieldValue).toString()..