Posted 21 February 2025, 6:46 am EST
Hi,
We can replicate the behavior you mentioned on our end. However, it is because of the technological differences between Microsoft Excel and SpreadJS. JavaScript can store numbers with lengths exceeding 15 digits, therefore the underlying value remains the same but the stripped display value is formatted like Excel.
This behavior can be customized by handling the values when entering into SpreadJS cells and converting the value to the floor value if the digit length of the number exceeds 15. Please refer to the code snippet below which works according to this workaround and rounds off the value as in Microsoft Excel
function handleLargeValues(sheet, row, col, value) {
if (
value !== "" &&
value !== null &&
value !== void 0 &&
!isNaN(value) &&
value.length > 15 &&
value.indexOf(".") < 0
) {
len = value.length;
spread.suspendEvent();
sheet.setValue(
row,
col,
Math.floor(+value / Math.pow(10, len - 15)) * Math.pow(10, len - 15)
);
spread.resumeEvent();
}
}
You can also refer to the attached code sample that uses the above code snippet and resolves the behavior difference (see below).
Please feel free to reach out if you encounter any further issues or require additional guidance.
Regards,
Ankit
RoundOff.zip