diff --git a/main/SS/Formula/Eval/TwoOperandNumeric/MultiplyEval.cs b/main/SS/Formula/Eval/TwoOperandNumeric/MultiplyEval.cs index ee1951ef2..923ad44a0 100644 --- a/main/SS/Formula/Eval/TwoOperandNumeric/MultiplyEval.cs +++ b/main/SS/Formula/Eval/TwoOperandNumeric/MultiplyEval.cs @@ -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); } } } \ No newline at end of file diff --git a/testcases/main/SS/Formula/Eval/TestMultiplyEval.cs b/testcases/main/SS/Formula/Eval/TestMultiplyEval.cs new file mode 100644 index 000000000..90c1e25cc --- /dev/null +++ b/testcases/main/SS/Formula/Eval/TestMultiplyEval.cs @@ -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); + } + + } + +} \ No newline at end of file diff --git a/testcases/main/SS/Formula/PTG/TestExternalNameReference.cs b/testcases/main/SS/Formula/PTG/TestExternalNameReference.cs index 2bdbd6005..a08140092 100644 --- a/testcases/main/SS/Formula/PTG/TestExternalNameReference.cs +++ b/testcases/main/SS/Formula/PTG/TestExternalNameReference.cs @@ -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); } }