EPPlus icon indicating copy to clipboard operation
EPPlus copied to clipboard

CEILING incorrectly rounds number already at specified significance.

Open PageEngine opened this issue 8 years ago • 2 comments

Applying the CEILING function to a value that is already rounded to the correct significance rounds one further multiple, when it should leave the value unchanged.

CEILING(100,100) returns 200 (Expected: 100) CEILING(12000,1000) returns 13000 (Expected: 12000)

Tested with the current NuGet stable release v.4.5.1 Expected values tested in current Office 365 Excel v.1708

(And just to note that the workaround ROUNDUP({Value}/{Multiple}, 0)*{Multiple} returns a correct result.)

PageEngine avatar May 11 '18 10:05 PageEngine

Fixed both Ceiling and Floor function with this invalid behavior

JanKallman avatar May 30 '18 20:05 JanKallman

Hi, You still have an error with CEILING(1 , 0.5) returns 1.5 (Expected: 1) We changed EPPlus/FormulaParsing/Excel/Functions/Math/Ceiling.cs in our local version this way:

//line 40 ValidateNumberAndSign(number, significance);

//New code if (number % significance == 0) { return CreateResult(number, DataType.Decimal); } else { double res; //quantity of full significance in number double quant = System.Math.Abs(System.Math.Truncate(number / significance));

if (number > 0) res = System.Math.Abs((quant + 1) * significance); //res goes up (quant + 1) else res = -1 * System.Math.Abs(quant * significance); // goes down

return CreateResult(res, DataType.Decimal); } //Commented out lines 41 to 60`

May be not really smart, but there is no error now. Thanks!

i0207 avatar Jul 26 '18 09:07 i0207