public static Decimal fromBigDecimal ( BigDecimal bd , int precision , int scale ) { bd = bd . setScale ( scale , RoundingMode . HALF_UP ) ; if ( bd . precision ( ) > precision ) { return null ; } long longVal = - 1 ; if ( precision <= MAX_COMPACT_PRECISION ) { longVal = bd . movePointRight ( scale ) . longValueExact ( ) ; } return new Decimal ( precision , scale , longVal , bd ) ; }
then precision is checked . if precision overflow it will return null