Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1055 Unexpected ROUNDDOWN function Result #1110

Merged
merged 5 commits into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion main/SS/Formula/Eval/TwoOperandNumeric/MultiplyEval.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ public class MultiplyEval : TwoOperandNumericOperation
{
public override double Evaluate(double d0, double d1)
{
return d0 * d1;
decimal dec0 = (decimal)d0;
decimal dec1 = (decimal)d1;

return decimal.ToDouble(dec0 * dec1);
}
}
}
55 changes: 55 additions & 0 deletions testcases/main/SS/Formula/Eval/TestMultiplyEval.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for Additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */

namespace TestCases.SS.Formula.Eval
{

using NUnit.Framework;
using NPOI.SS.Formula.Eval;
using TestCases.SS.Formula.Functions;

/**
* Test for multiply operator Evaluator.
*
*
*/
[TestFixture]
public class TestMultiplyEval
{

private static void Confirm(ValueEval arg0, ValueEval arg1, double expectedResult)
{
ValueEval[] args = {
arg0, arg1,
};

double result = NumericFunctionInvoker.Invoke(EvalInstances.Multiply, args, 0, 0);

Assert.AreEqual(expectedResult, result, 0);
}
[Test]
public void TestBasic()
{
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");

// issue #1055, use decimal to handle precision issue like (20000 * 0.000027 = 0.539999 in double)
Confirm(new NumberEval(20000), new NumberEval(0.000027), 0.54);
}

}

}
3 changes: 2 additions & 1 deletion testcases/main/SS/Formula/PTG/TestExternalNameReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public void TestEvaluate()
Evaluator.EvaluateFormulaCell(ccell);
Evaluator.EvaluateFormulaCell(tccell);
Assert.AreEqual(NEW_PART_COST, uccell.NumericCellValue);
Assert.AreEqual(NEW_PART_COST * NEW_QUANT, ccell.NumericCellValue);
double ctotal = decimal.ToDouble((decimal)NEW_PART_COST * (decimal)NEW_QUANT);
Assert.AreEqual(ctotal, ccell.NumericCellValue);
Assert.AreEqual(NEW_PART_COST * NEW_QUANT * MARKUP_COST_2, tccell.NumericCellValue);
}
}
Expand Down
Loading