code: public static BigDecimal validateBigDecimalValue(BigDecimal newValue, int expectedPrecision,int expectedScale)
      {
          if(newValue != null)
          {
              int scale = newValue.scale();
              int precision = newValue.precision();
  
              if(isAbsBetweenZeroAndOne(newValue))
              {
                  newValue = newValue.setScale(expectedScale, java.math.RoundingMode.HALF_UP);
              }
              else
              {
                  int integerPart = precision - scale;
                  int expectedIntegerPart = expectedPrecision - expectedScale;
  
                  if (integerPart > expectedIntegerPart)
                  {
                      throw new MithraBusinessException("Invalid BigDecimal: " + newValue.toPlainString() + ". Expected a BigDecimal with (precision, scale) of: (" + expectedPrecision + "," + expectedScale + ")");
                  }
                  if (scale != expectedScale || precision > expectedPrecision)
                  {
                      scale = expectedScale;
                      newValue = newValue.setScale(scale, java.math.RoundingMode.HALF_UP);
                  }
              }
          }
          return newValue;
      }
docs: todo: moh - review this logic, not sure if the rounding is correct for all cases