use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestPmt method confirm.
private static void confirm(double expected, double rate, double nper, double pv, double fv, boolean isBeginning) {
ValueEval[] args = { new NumberEval(rate), new NumberEval(nper), new NumberEval(pv), new NumberEval(fv), new NumberEval(isBeginning ? 1 : 0) };
confirm(expected, invokeNormal(args));
}
use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestTrunc method testTruncWithWholeNumber.
public void testTruncWithWholeNumber() {
ValueEval[] args = { new NumberEval(200), new NumberEval(2) };
@SuppressWarnings("static-access") ValueEval result = F.TRUNC.evaluate(args, -1, (short) -1);
assertEquals("TRUNC", (new NumberEval(200d)).getNumberValue(), ((NumberEval) result).getNumberValue());
}
use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class TestXYNumericFunction method testBasic.
public void testBasic() {
ValueEval[] xValues = { new NumberEval(1), new NumberEval(2) };
ValueEval areaEvalX = createAreaEval(xValues);
confirm(SUM_SQUARES, areaEvalX, areaEvalX, 10.0);
confirm(DIFF_SQUARES, areaEvalX, areaEvalX, 0.0);
confirm(SUM_SQUARES_OF_DIFFS, areaEvalX, areaEvalX, 0.0);
ValueEval[] yValues = { new NumberEval(3), new NumberEval(4) };
ValueEval areaEvalY = createAreaEval(yValues);
confirm(SUM_SQUARES, areaEvalX, areaEvalY, 30.0);
confirm(DIFF_SQUARES, areaEvalX, areaEvalY, -20.0);
confirm(SUM_SQUARES_OF_DIFFS, areaEvalX, areaEvalY, 8.0);
}
use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class EDate method evaluate.
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
if (args.length != 2) {
return ErrorEval.VALUE_INVALID;
}
try {
double startDateAsNumber = getValue(args[0]);
int offsetInMonthAsNumber = (int) getValue(args[1]);
Date startDate = DateUtil.getJavaDate(startDateAsNumber);
Calendar calendar = LocaleUtil.getLocaleCalendar();
calendar.setTime(startDate);
calendar.add(Calendar.MONTH, offsetInMonthAsNumber);
return new NumberEval(DateUtil.getExcelDate(calendar.getTime()));
} catch (EvaluationException e) {
return e.getErrorEval();
}
}
use of org.apache.poi.ss.formula.eval.NumberEval in project poi by apache.
the class EDate method getValue.
private double getValue(ValueEval arg) throws EvaluationException {
if (arg instanceof NumberEval) {
return ((NumberEval) arg).getNumberValue();
}
if (arg instanceof BlankEval) {
return 0;
}
if (arg instanceof RefEval) {
RefEval refEval = (RefEval) arg;
if (refEval.getNumberOfSheets() > 1) {
// Multi-Sheet references are not supported
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
ValueEval innerValueEval = refEval.getInnerValueEval(refEval.getFirstSheetIndex());
if (innerValueEval instanceof NumberEval) {
return ((NumberEval) innerValueEval).getNumberValue();
}
if (innerValueEval instanceof BlankEval) {
return 0;
}
}
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
Aggregations