protected BigDecimal trunc(BigDecimal input, int scale) {
    BigDecimal output = new BigDecimal(0);
    BigDecimal pow = BigDecimal.valueOf(Math.pow(10, Math.abs(scale)));
    if (scale >= 0) {
      pow = BigDecimal.valueOf(Math.pow(10, scale));
      if (scale != 0) {
        long longValue = input.multiply(pow).longValue();
        output = BigDecimal.valueOf(longValue).divide(pow);
      } else {
        output = BigDecimal.valueOf(input.longValue());
      }
    } else {
      long longValue2 = input.divide(pow).longValue();
      output = BigDecimal.valueOf(longValue2).multiply(pow);
    }
    return output;
  }
GenericUDFTrunc.

Returns the first day of the month which the date belongs to. The time part of the date will be
ignored.
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFTrunc.java