@Override
  public int encode(PositionedByteRange dst, Number val) {
    if (null == val) {
      return OrderedBytes.encodeNull(dst, order);
    } else if (val instanceof BigDecimal) {
      return OrderedBytes.encodeNumeric(dst, (BigDecimal) val, order);
    } else if (val instanceof BigInteger) {
      return OrderedBytes.encodeNumeric(dst, new BigDecimal((BigInteger) val), order);
    } else if (val instanceof Double || val instanceof Float) {
      return OrderedBytes.encodeNumeric(dst, val.doubleValue(), order);
    } else {
      // TODO: other instances of Numeric to consider?
      return OrderedBytes.encodeNumeric(dst, val.longValue(), order);
    }
  }
Creates a new {@link Number} of arbitrary precision and variable-length encoding.
@param order the {@link Order} to use
hbase-common/src/main/java/org/apache/hadoop/hbase/types/OrderedNumeric.java