protected BigDecimal trunc(BigDecimal input) {
    BigDecimal pow = BigDecimal.valueOf(Math.pow(10, Math.abs(scale)));

    if (scale >= 0) {
      if (scale != 0) {
        long longValue = input.multiply(pow).longValue();
        return BigDecimal.valueOf(longValue).divide(pow);
      } else {
        return BigDecimal.valueOf(input.longValue());
      }
    } else {
      long longValue2 = input.divide(pow).longValue();
      return BigDecimal.valueOf(longValue2).multiply(pow);
    }
  }
Vectorized implementation of trunc(number, scale) function for float/double input
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/TruncFloat.java