public static BigDecimal getBigDecimalOrNull(Object value) {
        if ( value instanceof BigDecimal ) {
            return (BigDecimal) value;
        }

        if ( value instanceof BigInteger ) {
            return new BigDecimal((BigInteger) value, MathContext.DECIMAL128);
        }

        if ( value instanceof Double || value instanceof Float ) {
            String stringVal = value.toString();
            if (stringVal.equals("NaN") || stringVal.equals("Infinity") || stringVal.equals("-Infinity")) {
                return null;
            }
            // doubleValue() sometimes produce rounding errors, so we need to use toString() instead
            // We also need to remove trailing zeros, if there are some so for 10d we get BigDecimal.valueOf(10)
            // instead of BigDecimal.valueOf(10.0).
            return new BigDecimal( removeTrailingZeros(value.toString()), MathContext.DECIMAL128 );
        }

        if ( value instanceof Number ) {
            return new BigDecimal( ((Number) value).longValue(), MathContext.DECIMAL128 );
        }

        if ( value instanceof String ) {
            try {
                // we need to remove leading zeros to prevent octal conversion
                return new BigDecimal(((String) value).replaceFirst("^0+(?!$)", ""), MathContext.DECIMAL128);
            } catch (NumberFormatException e) {
                return null;
            }
        }

        return null;
    }
@Test
    void getBigDecimalOrNull() {
        assertThat(NumberEvalHelper.getBigDecimalOrNull(10d)).isEqualTo(new BigDecimal("10"));
        assertThat(NumberEvalHelper.getBigDecimalOrNull(10.00000000D)).isEqualTo(new BigDecimal("10"));
        assertThat(NumberEvalHelper.getBigDecimalOrNull(10000000000.5D)).isEqualTo(new BigDecimal("10000000000.5"));
    }