try {
double d0 = singleOperandEvaluate(arg0, srcRowIndex, srcColumnIndex);
double d1 = singleOperandEvaluate(arg1, srcRowIndex, srcColumnIndex);
- double multi = Math.pow(10d,d1);
- if(d0 < 0) result = -Math.floor(-d0 * multi) / multi;
- else result = Math.floor(d0 * multi) / multi;
+ result = MathX.roundDown(d0, (int)d1);
checkValue(result);
}catch (EvaluationException e) {
return e.getErrorEval();
assertEquals("TRUNC", (new NumberEval(2.612d)).getNumberValue(), ((NumberEval)result).getNumberValue());
}
+ @Test
+ public void testTruncWithProblematicDecimalNumber() {
+ ValueEval[] args = { new NumberEval(0.29), new NumberEval(2) };
+ ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1);
+ assertEquals("TRUNC", (new NumberEval(0.29d)).getNumberValue(), ((NumberEval)result).getNumberValue());
+ }
+
+ @Test
+ public void testTruncWithProblematicCalculationResult() {
+
+ ValueEval[] args = { new NumberEval(21.624d / 24d + .009d), new NumberEval(2) };
+ ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short)-1);
+ assertEquals("TRUNC", (new NumberEval(0.91d)).getNumberValue(), ((NumberEval)result).getNumberValue());
+ }
+
@Test
public void testTruncWithDecimalNumberOneArg() {
ValueEval[] args = { new NumberEval(2.612777) };