matthew-formosa-gig commented on a change in pull request #3343: Nifi 5572 URL: https://github.com/apache/nifi/pull/3343#discussion_r292976345
########## File path: nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java ########## @@ -1378,6 +1393,61 @@ public static boolean isCharacterTypeCompatible(final Object value) { return value != null && (value instanceof Character || (value instanceof CharSequence && ((CharSequence) value).length() > 0)); } + public static BigDecimal toDecimal(final Object value, final String fieldName) { + if (value == null) { + return null; + } + + if (value instanceof BigDecimal) { + return (BigDecimal)value; + } + + if (value instanceof String) { + return new BigDecimal((String) value); + } + + if(value instanceof Number){ + return new BigDecimal(((Number)value).doubleValue()); + } + Review comment: I would also check for precision here and throw an `IllegalTypeConversionException` if the required precision is less than the precision of the converted `BigDecimal`. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services