[inner-1844] Fix the round/truncate function problem (cherry pick) (#3351)

This commit is contained in:
wenyh
2022-08-12 15:26:09 +08:00
committed by wd2365151147
parent ee3d43205e
commit e047959014

View File

@@ -55,8 +55,7 @@ public abstract class ItemFuncRoundOrTruncate extends ItemFuncNum1 {
@Override
public BigDecimal decimalOp() {
hybridType = ItemResult.DECIMAL_RESULT;
if (args.get(0).isNull() || args.get(1).isNull()) {
this.nullValue = true;
if (nullValue = (args.get(0).isNull() || args.get(1).isNull())) {
return BigDecimal.ZERO;
}
BigDecimal val0 = args.get(0).valDecimal();
@@ -130,7 +129,7 @@ public abstract class ItemFuncRoundOrTruncate extends ItemFuncNum1 {
BigInteger bi = value.toBigInteger();
return new BigDecimal(getIntRound(bi, round));
} else {
return value.setScale(round, RoundingMode.FLOOR);
return value.setScale(round, truncate ? RoundingMode.FLOOR : RoundingMode.HALF_UP);
}
}
}