public static byte[] toBytes(BigDecimal val) {
    byte[] valueBytes = val.unscaledValue().toByteArray();
    byte[] result = new byte[valueBytes.length + SIZEOF_INT];
    int offset = putInt(result, 0, val.scale());
    putBytes(result, offset, valueBytes, 0, valueBytes.length);
    return result;
  }
public static byte [ ] toBytes ( BigDecimal val ) { byte [ ] valueBytes = val . unscaledValue ( ) . toByteArray ( ) ; byte [ ] result = new byte [ valueBytes . length + SIZEOF_INT ] ; int offset = putInt ( result , 0 , val . scale ( ) ) ; putBytes ( result , offset , valueBytes , 0 , valueBytes . length ) ; return result ; }
Convert a BigDecimal value to a byte array.

@param val
@return the byte array