@HiveDecimalWritableVersionV2
  public String toString(
      byte[] scratchBuffer) {
    if (!isSet()) {
      throw new RuntimeException("no value set");
    }
    if (fastSerializationScale() != -1) {

      // Use the serialization scale and format the string with trailing zeroes (or
      // round the decimal) if necessary.
      return
          fastToFormatString(
              fastSerializationScale(),
              scratchBuffer);
    } else {
      return
          fastToString(scratchBuffer);
    }
  }
Allocate scratchLongs with HiveDecimal.SCRATCH_LONGS_LEN longs.
And, allocate scratch scratchBuffer with HiveDecimal.SCRATCH_BUFFER_LEN_BIG_INTEGER_BYTES bytes.
storage-api/src/java/org/apache/hadoop/hive/serde2/io/HiveDecimalWritable.java