TestExcel.xlsx.After import, some formula cells produce different results than Excel when the intermediate result is very close to zero.
Observed example from the attached file:
In Excel:
E1 = 0E2 = 0F1 = 55110.305475240835In Spreadsheet after import:
E1 = 0.00000000004366E2 = 0.000000000043660000000000000000F1 = 0Spreadsheet should match Excel results for the imported workbook, including cases where formulas evaluate to values extremely close to zero.
The issue appears related to formula recalculation after import and handling of floating-point precision near zero.
In the attached file:
The imported numeric inputs are:
A1 = 79590.518373344006B1 = 0.16372664029103301C1 = 4D1 = 82665.458212861093The formula in E1 is:
A1*(1+B1)^(1/C1)-D1Excel stores the result as 0, but Spreadsheet recalculates it to a very small positive number, which then changes the dependent IF result in F1.
TestExcel.xlsx <script>
const CANCELLATION_EPSILON = Number.EPSILON * 4;
function collapseCancellationError(result, left, right) {
const scale = Math.max(Math.abs(left), Math.abs(right));
if (!scale || result === 0) {
return result;
}
return Math.abs(result) <= CANCELLATION_EPSILON * scale ? 0 : result;
}
const { defineFunction } = KendoSpreadsheetCommon;
defineFunction('binary+', function(a, b) {
return collapseCancellationError(a + b, a, b);
}).args([
['*a', ['or', 'number', ['null', 0]]],
['*b', ['or', 'number', ['null', 0]]]
]);
defineFunction('binary-', function(a, b) {
return collapseCancellationError(a - b, a, b);
}).args([
['*a', ['or', 'number', ['null', 0]]],
['*b', ['or', 'number', ['null', 0]]]
]);
</script>