} else if (val instanceof BigDecimal) {
if (outputType.getPrimitiveTypeName().equals(Type.TypeName.PRECISE)) {
// If we know the scale associated with the result PRECISE object,
// make sure we use the appropriate scale (the scale used during
// computation may be overly precise as a result of math operations).
PreciseType preciseType = PreciseType.toPreciseType(outputType);
BigDecimal bigDec = (BigDecimal) val;
return bigDec.setScale(preciseType.getScale(), RoundingMode.HALF_EVEN).toString();
} else {
// Not sure what would cause a BigDecimal to be coerced to some
// non-PRECISE output type, but in any case, it will be represented
// as a string.
return val.toString();