handsontable-sum-round-error
by thilgen
HTML
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/handsontable/dist/handsontable.full.min.css" />
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/handsontable/dist/handsontable.full.min.js"></script>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="example"></div>
</body>
</html>
JavaScript
const hyperformulaInstance = HyperFormula.buildEmpty({
licenseKey: 'internal-use-in-handsontable',
});
function printDebugInfo() {
let debug = 'Handsontable:';
debug += ` v${Handsontable.version}`;
debug += ` (${Handsontable.buildDate})`;
debug += `\nHyperFormula: ${HyperFormula.version}`;
console.log(debug)
}
printDebugInfo()
var container = document.getElementById('example')
container.hot = new Handsontable(
container,
{
formulas: {
engine: hyperformulaInstance,
sheetName: container.id
},
data: [
[1795.00],
[-107.70],
[-115.00],
]
}
)
console.log("SUM(A:A) - 1 Time")
let total1 = 0
for (let idx = 0 ; idx < 1 ; idx++) {
const sum = hyperformulaInstance.calculateFormula('=SUM(A:A)', 0)
const sumFixed = sum.toFixed(10)
const sumExp = sum.toExponential(10)
console.log(' hyperformulaInstance.calculateFormula(A:A) returned ' + sum + " Fixed: " + sumFixed + " Exp: " + sumExp)
total1 += sum
}
console.log(" total1: " + total1)
console.log("SUM(A:A) - 6 Times")
let total6 = 0
for (let idx = 0 ; idx < 6 ; idx++) {
const sum = hyperformulaInstance.calculateFormula('=SUM(A:A)', 0)
const sumFixed = sum.toFixed(10)
const sumExp = sum.toExponential(10)
console.log(' hyperformulaInstance.calculateFormula(A:A) returned ' + sum + " Fixed: " + sumFixed + " Exp: " + sumExp)
total6 += sum
}
console.log(" total6: " + total6)
console.log("SUM(A:A) - 7 Times")
let total7 = 0
for (let idx = 0 ; idx < 7 ; idx++) {
const sum = hyperformulaInstance.calculateFormula('=SUM(A:A)', 0)
const sumFixed = sum.toFixed(10)
const sumExp = sum.toExponential(10)
console.log(' hyperformulaInstance.calculateFormula(A:A) returned ' + sum + " Fixed: " + sumFixed + " Exp: " + sumExp)
total7 += sum
}
console.log(" total7: " + total7)