class Round extends AbtractMultiParameterMathFunction {
@Override
protected Expression evaluate(List<Expression> splitParameters, ProblemsHandler problemsHandler, FunctionExpression functionCall, HiddenTokenAwareTree parentToken) {
NumberExpression parameter = (NumberExpression) splitParameters.get(0);
Double oValue = parameter.getValueAsDouble();
String suffix = parameter.getSuffix();
Dimension dimension = parameter.getDimension();
if (oValue.isInfinite() || oValue.isNaN())
return new NumberExpression(parentToken, oValue, suffix, null, dimension);
NumberExpression fraction = (NumberExpression) (splitParameters.size() > 1 ? splitParameters.get(1) : null);
if (fraction != null) {
double pow = Math.pow(10, fraction.getValueAsDouble());
oValue = Math.round(oValue * pow) / pow;
} else {
oValue = (double) Math.round(oValue);
}
return new NumberExpression(parentToken, oValue, suffix, null, dimension);
}