Return BigDecimal with given parameters.

@param scale
@param rounding
@param stripTrailingZeros
@return BigDecimal
971502
public BigDecimal toBigDecimal(Integer scale, Rounding rounding, boolean stripTrailingZeros) {
	    out = this.in;
	    
	    if (scale != null && rounding != null)
	        out = out.setScale(scale, rounding.getBigDecimalRound());
	    else if (scale != null && rounding == null)
	        out = out.setScale(scale);
	    
	    if (stripTrailingZeros)
	        out = out.stripTrailingZeros();
	    
	    return out;
	}
907870
public static BigDecimal toBigDecimal(String number) {
		return (null == number) ? BigDecimal.ZERO : new BigDecimal(number);
	}
307668
@Override
    public BigDecimal apply(ChronoEntity<?> context) {

        long value = context.get(this.element).longValue();
        long min = context.getMinimum(this.element).longValue();
        long max = context.getMaximum(this.element).longValue();

        if (value > max) {
            value = max; // Schutz gegen Anomalien
        }

        if (value == min) {
            return BigDecimal.ZERO;
        }

        if (
            this.extendedRange
            && (context instanceof PlainTime)
            && !PlainTime.class.cast(context).hasReducedRange(this.element)
        ) {
            if (value == max) {
                return BigDecimal.ONE;
            }
            max--;
        }

        BigDecimal count = new BigDecimal(value - min).setScale(15, RoundingMode.UNNECESSARY);
        BigDecimal divisor = new BigDecimal(max - min + 1);

        return count.divide(divisor, RoundingMode.HALF_UP).stripTrailingZeros();

    }
1101662
public static double subtract(double minuend, double reduction, int scale) {
        BigDecimal minuendBd = new BigDecimal(Double.toString(minuend));
        BigDecimal reductionBd = new BigDecimal(Double.toString(reduction));
        MathContext mathContext = new MathContext(scale, RoundingMode.HALF_UP);
        return minuendBd.subtract(reductionBd, mathContext).doubleValue();
    }
1135899
public final static Function<BigDecimal, BigDecimal> divideBy(byte divisor, RoundingMode roundingMode) {
        return divideBy(Byte.valueOf(divisor), roundingMode);
    }
993429
public static BigDecimal div(Number v1, Number v2, int scale, RoundingMode roundingMode) {
		return div(v1.toString(), v2.toString(), scale, roundingMode);
	}
92161
public static BigDecimal inverse(final BigDecimal value, final int scale, final int rounding) {
        if (isNotZero(value)) {
            return BigDecimal.ONE.divide(value, scale, rounding);
        }
        return null;
    }
14085
private static BigDecimal currentTokenAsJavaDecimal(JsonParser parser, int precision, int scale)
            throws IOException
    {
        BigDecimal result;
        switch (parser.getCurrentToken()) {
            case VALUE_NULL:
                return null;
            case VALUE_STRING:
            case FIELD_NAME:
                result = new BigDecimal(parser.getText());
                result = result.setScale(scale, HALF_UP);
                break;
            case VALUE_NUMBER_FLOAT:
            case VALUE_NUMBER_INT:
                result = parser.getDecimalValue();
                result = result.setScale(scale, HALF_UP);
                break;
            case VALUE_TRUE:
                result = BigDecimal.ONE.setScale(scale, HALF_UP);
                break;
            case VALUE_FALSE:
                result = BigDecimal.ZERO.setScale(scale, HALF_UP);
                break;
            default:
                throw new JsonCastException(format("Unexpected token when cast to DECIMAL(%s,%s): %s", precision, scale, parser.getText()));
        }

        if (result.precision() > precision) {
            // TODO: Should we use NUMERIC_VALUE_OUT_OF_RANGE instead?
            throw new PrestoException(INVALID_CAST_ARGUMENT, format("Cannot cast input json to DECIMAL(%s,%s)", precision, scale));
        }
        return result;
    }
509307
public static BigDecimal setScale(final BigDecimal bd, final int scale) {
        return setScale(bd, scale, BigDecimal.ROUND_HALF_UP);
    }
1306291
private static long floorDiv(long x, long y) {
    return BigDecimal.valueOf(x).divide(BigDecimal.valueOf(y), 0, RoundingMode.FLOOR).longValue();
  }
407783
public static BigDecimal div(BigDecimal v1, BigDecimal v2, int scale, RoundingMode roundingMode) {
		Assert.notNull(v2, "Divisor must be not null !");
		if (null == v1) {
			return BigDecimal.ZERO;
		}
		if (scale < 0) {
			scale = -scale;
		}
		return v1.divide(v2, scale, roundingMode);
	}
553487
public static double scaleValue(double value, int decimals) {
    BigDecimal bd = BigDecimal.valueOf(value);
    return bd.setScale(decimals, RoundingMode.HALF_UP).doubleValue();
  }
156344
public static BigDecimal bigDecimalValue(BigDecimal val)
    {
        if (val == null
            || val.getClass() == BigDecimal.class)
        {
            return val;
        }
        return new BigDecimal(val.unscaledValue(), val.scale());
    }
425868
public static BigDecimal deserializeBigDecimalFromString(String decimal) throws IOException
    {
        if (decimal == null) {
            return null;
        }
        BigDecimal bd = new BigDecimal(decimal);
        // if the scale is too large, check for trailing zeros
        if (bd.scale() > kDefaultScale) {
            bd = bd.stripTrailingZeros();
            if (bd.scale() > kDefaultScale) {
                bd = roundToScale(bd, kDefaultScale, getRoundingMode());
            }
        }
        // enforce scale 12 to make the precision check right
        if (bd.scale() < kDefaultScale) {
            bd = bd.setScale(kDefaultScale);
        }
        if (bd.precision() > 38) {
            throw new RuntimeException(
                    "Decimal " + bd + " has more than " + kDefaultPrecision + " digits of precision.");
        }
        return bd;
    }
1316864
public static BigDecimal round(String numberStr, int scale, RoundingMode roundingMode) {
		Assert.notBlank(numberStr);
		if (scale < 0) {
			scale = 0;
		}
		return round(toBigDecimal(numberStr), scale, roundingMode);
	}
338382
private static BigDecimal roundedTenPower(int qsign, int raise, int scale, int preferredScale) {
        if (scale > preferredScale) {
            int diff = scale - preferredScale;
            if(diff < raise) {
                return scaledTenPow(raise - diff, qsign, preferredScale);
            } else {
                return valueOf(qsign,scale-raise);
            }
        } else {
            return scaledTenPow(raise, qsign, scale);
        }
    }
959131
public static BigDecimal rounddown(EvaluationContext ctx, Object number, Object numDigits) {
        BigDecimal _number = Conversions.toDecimal(number, ctx);
        int _numDigits = Conversions.toInteger(numDigits, ctx);

        return ExpressionUtils.decimalRound(_number, _numDigits, RoundingMode.DOWN);
    }