turcsanyip commented on a change in pull request #4223:
URL: https://github.com/apache/nifi/pull/4223#discussion_r414812833



##########
File path: 
nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java
##########
@@ -1266,6 +1279,46 @@ public static boolean isBooleanTypeCompatible(final 
Object value) {
         return false;
     }
 
+    public static BigDecimal toBigDecimal(final Object value, final String 
fieldName) {
+        if (value == null) {
+            return null;
+        }
+
+        if (value instanceof BigDecimal) {
+            return (BigDecimal) value;
+        }
+
+        if (value instanceof Number) {
+            final Number number = (Number) value;
+
+            if (number instanceof Byte
+                    || number instanceof Short
+                    || number instanceof Integer
+                    || number instanceof Long) {
+                return BigDecimal.valueOf(number.longValue());
+            }
+
+            if (number instanceof BigInteger) {
+                return new BigDecimal((BigInteger) number);
+            }
+
+            if (number instanceof Float || number instanceof Double) {
+                return BigDecimal.valueOf(number.doubleValue());

Review comment:
       `BigDecimal.valueOf(double)` seems to me fine.
   It calls `new BigDecimal(Double.toString(val))` in the background, which is 
the proposed solution.
   I think the problematic way would be the `new BigDecimal(double)` 
constructor, not `BigDecimal.valueOf(double)`.
   
   `new BigDecimal(number.toString())` could also be used.
   




----------------------------------------------------------------
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:
[email protected]


Reply via email to